<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Alunduil&#039;s Hosting &#187; Linux Guides</title>
	<atom:link href="http://www.alunduil.com/category/linux-guides/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alunduil.com</link>
	<description>Gentoo Hackery and Other Fun ...</description>
	<lastBuildDate>Sun, 01 May 2011 22:00:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Apache Rewrite Cheat Sheet</title>
		<link>http://www.alunduil.com/2011/05/01/apache-rewrite-cheat-sheet/</link>
		<comments>http://www.alunduil.com/2011/05/01/apache-rewrite-cheat-sheet/#comments</comments>
		<pubDate>Sun, 01 May 2011 22:00:34 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[rewritecond]]></category>
		<category><![CDATA[rewritelog]]></category>
		<category><![CDATA[rewriteloglevel]]></category>
		<category><![CDATA[rewriterule]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=410</guid>
		<description><![CDATA[Introduction I was recently requested to document common apache rewrite pitfalls and examples and crafted the following document as a response.  It is intended as a two page document (Rewrite Cheat Sheet) where the first page is a reference guide of commonly used rewrite variables and flags and the second page is a short list of <a href='http://www.alunduil.com/2011/05/01/apache-rewrite-cheat-sheet/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { margin: 0.79in } 		P { margin-bottom: 0.08in } 		P.western { font-size: 10pt } 		P.cjk { font-size: 10pt } 		H1 { margin-bottom: 0.08in } 		H1.western { font-family: "Liberation Sans", sans-serif; font-size: 15pt } 		H1.cjk { font-family: "DejaVu Sans"; font-size: 16pt } 		H1.ctl { font-family: "DejaVu Sans"; font-size: 16pt } 		H2 { margin-bottom: 0.08in } 		H2.western { font-family: "Liberation Sans", sans-serif; font-size: 12pt; font-style: italic } 		H2.cjk { font-size: 14pt; font-style: italic; font-weight: normal } 		H2.ctl { font-size: 14pt; font-style: italic; font-weight: normal } 		H3 { margin-bottom: 0.08in } 		H3.western { font-family: "Liberation Sans", sans-serif; font-size: 12pt } 		CODE.cjk { font-family: "DejaVu Sans", monospace } --></p>
<h1>Introduction</h1>
<p>I was recently requested to document common apache rewrite pitfalls and examples and crafted the following document as a response.  It is intended as a two page document (<a href="http://www.alunduil.com/wp-content/uploads/2011/04/Rewrite-Cheat-Sheet.pdf">Rewrite Cheat Sheet</a>) where the first page is a reference guide of commonly used rewrite variables and flags and the second page is a short list of examples, gotchas, and troubleshooting advice.</p>
<h1>Rewrite Cheat Sheet</h1>
<h2>Common Variables</h2>
<h3>HTTP Headers</h3>
<ul>
<li>HTTP_USER_AGENT</li>
<li>HTTP_REFERER</li>
<li>HTTP_COOKIE</li>
<li>HTTP_FORWARDED</li>
<li>HTTP_HOST</li>
<li>HTTP_PROXY_CONNECTION</li>
<li>HTTP_ACCEPT</li>
</ul>
<h3>connection &amp; request</h3>
<ul>
<li>REMOTE_ADDR</li>
<li>REMOTE_HOST</li>
<li>REMOTE_PORT</li>
<li>REMOTE_USER</li>
<li>REMOTE_IDENT</li>
<li>REQUEST_METHOD</li>
<li>SCRIPT_FILENAME</li>
<li>PATH_INFO</li>
<li>QUERY_STRING</li>
<li>AUTH_TYPE</li>
</ul>
<h3>server internals</h3>
<ul>
<li>DOCUMENT_ROOT</li>
<li>SERVER_ADMIN</li>
<li>SERVER_NAME</li>
<li>SERVER_ADDR</li>
<li>SERVER_PORT</li>
<li>SERVER_PROTOCOL</li>
<li>SERVER_SOFTWARE</li>
</ul>
<h3>date and time</h3>
<ul>
<li>TIME_YEAR</li>
<li>TIME_MON</li>
<li>TIME_DAY</li>
<li>TIME_HOUR</li>
<li>TIME_MIN</li>
<li>TIME_SEC</li>
<li>TIME_WDAY</li>
<li>TIME</li>
</ul>
<h3>specials</h3>
<ul>
<li>API_VERSION</li>
<li>THE_REQUEST</li>
<li>REQUEST_URI</li>
<li>REQUEST_FILENAME</li>
<li>IS_SUBREQ</li>
<li>HTTPS</li>
</ul>
<h2>Variable Descriptions</h2>
<ul>
<li><code>REQUEST_FILENAME</code>
<ul>
<li>The full local filesystem path to the file 		or script matching the request, if this has already been determined 		by the server at the time <code>REQUEST_FILENAME</code> is referenced. Otherwise, such as when used in virtual host 		context, the same value as <code>REQUEST_URI</code>.</li>
</ul>
</li>
<li><code>HTTPS</code>
<ul>
<li>Will contain the text &#8220;on&#8221; if the 		connection is using SSL/TLS, or &#8220;off&#8221; otherwise. (This 		variable can be safely used regardless of whether or not <code>mod_ssl</code> is loaded).</li>
</ul>
</li>
</ul>
<h2>Flag Descriptions</h2>
<ul>
<li>&#8216;<code>nocase|NC</code>&#8216; (<strong>n</strong>o 	<strong>c</strong>ase) :: This makes the test case-insensitive &#8211; 	differences between &#8216;A-Z&#8217; and &#8216;a-z&#8217; are ignored, both in the 	expanded <em>TestString</em> and the <em>CondPattern</em>.</li>
<li>&#8216;<code>ornext|OR</code>&#8216; (<strong>or</strong> next condition) (<strong>RewriteCond Only</strong>) :: Use this to combine 	rule conditions with a local OR instead of the implicit AND.</li>
<li><strong>&#8216;last|L&#8217;</strong> :: Stop the rewriting 	process immediately and don&#8217;t apply any more rules.</li>
<li><strong>&#8216;proxy|P&#8217;</strong> :: Force the substitution 	URL to be internally sent as a proxy request.</li>
<li><em><strong>&#8216;qsappend|QSA</strong></em><em>&#8216;</em><em> :: Appends any query string created in the rewrite target to any 	query string that was in the original request URL.</em></li>
<li><em>&#8216;</em><em><strong>redirect|R[=code]</strong></em><em>&#8216; 	:: </em><em>Forces an external redirect, optionally with the 	specified HTTP status code.</em></li>
<li><em>&#8216;</em><em><strong>forbidden|F</strong></em><em>&#8216;</em><em> :: Returns a 403 FORBIDDEN response to the client browser.</em></li>
</ul>
<h2>Good Examples</h2>
<ul>
<li>Adding www to all requests
<ul>
<li>RewriteCond %{HTTP_HOST} !^www [NC]</li>
<li>RewriteRule ^ 		http://www.%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]</li>
</ul>
</li>
<li>Forcing all requests to HTTPS
<ul>
<li>RewriteCond %{HTTPS} off</li>
<li>RewriteRule ^ 		https://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]</li>
</ul>
</li>
<li>Redirect a specific subweb to another domain
<ul>
<li>RewriteRule ^/?subweb/(.*) 		http://other.example.com/$1 [R,L,QSA]</li>
</ul>
</li>
<li>Block specific IPs from access
<ul>
<li>RewriteCond %{REMOTE_ADDR} ^127\.0\.0</li>
<li>RewriteRule ^ &#8211; [F,L]</li>
</ul>
</li>
<li>Creating a filesystem alias with modrewrite
<ul>
<li>RewriteRule ^/?alias/(.*) 		/var/www/vhosts/$1/httpdocs/$1 [L,R]</li>
</ul>
</li>
<li>A condition to stop CMS software from 	over-riding fullstatus (added before the offending rewriterule)
<ul>
<li>RewriteCond ${REQUEST_URI} !server-status 		[NC]</li>
</ul>
</li>
</ul>
<h2>Bad Examples</h2>
<ul>
<li>Recursive rewrite
<ul>
<li>RewriteRule ^ 		http://www.%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]</li>
</ul>
</li>
</ul>
<h2>Gotchas</h2>
<ul>
<li>Some rewrites may conflict with existing 	rewrites provided by many CMS packages (wordpress, drupal, joomla, 	etc).  Check for any existing rewrites in a .htaccess file.</li>
<li>Rewriterule and rewritecond can only be used 	in the following contexts: server config, virtual host, directory, 	.htaccess</li>
</ul>
<h2>Common Troubleshooting</h2>
<ul>
<li>Enable the rewrite logs with RewriteLog and 	RewriteLevel
<ul>
<li>RewriteLog &lt;file path&gt;</li>
<li>RewriteLogLevel 3 # ranges from 0 to 9</li>
</ul>
</li>
<li>Check your regular expressions against a PCRE 	checker (they are very bountiful on the Internet 	[http://tinyurl.com/3hop7xu]).</li>
<li>Utilize curl to test redirects (R), `curl -I 	example.com`</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/05/01/apache-rewrite-cheat-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Optimizing Gentoo CFLAGS (Part II)</title>
		<link>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/</link>
		<comments>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 23:00:46 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[cflags]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=205</guid>
		<description><![CDATA[Introduction As I mentioned las﻿t time, you want to be comfortable with the existing documentation on CFLAGS before going crazy trying to play with. It also helps to have a good understanding of what you&#8217;re doing to the code when you modify these &#8220;sacred&#8221; parameters. Alright, now that the CYA is out of the way <a href='http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>As I mentioned <a href="http://www.alunduil.com/2009/12/18/optimizing-gentoo-cflags/">las﻿t time</a>, you want to be comfortable with the existing documentation on CFLAGS before going crazy trying to play with.  It also helps to have a good understanding of what you&#8217;re doing to the code when you modify these &#8220;sacred&#8221; parameters.</p>
<p>Alright, now that the CYA is out of the way let&#8217;s take this one step further.  Last time we talked about figuring out which instruction sets your processor understood and how to figure out what `-m` flags would get those instruction sets into the binaries on your system.  This time we&#8217;ll be talking about making sure those same flags are in your use flags (just to be sure they&#8217;re picked up by the system).</p>
<h1>Finding Flag Names</h1>
<p>So how do we find the flags that do what we want?  Well, as always BASH is our friend and can be used to find this answer in a mostly automated fashion:</p>
<pre>. /etc/make.conf &amp;&amp; gcc -Q -c -v ${CFLAGS} --help=target | grep enabled</pre>
<p>This displays the currently enabled flags based on your CFLAGS parameter and allows us to find which flags have use flags with the following one liner:</p>
<pre>gawk '/-m.*/ { print $1 }' | cut -d 'm' --complement -f 1 | xargs -I{} equery h "{}"</pre>
<h1>Conclusion</h1>
<p>Using a little scripting we can extract the necessary information to quickly determine if there are any use flags we should be adding for particular compiler flags that our system might support.  With this last level of optimization beyond the previous time&#8217;s we should be ready to move on to -O3 (for the daring) and watch our machine&#8217;s nose bleed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/20/optimizing-gentoo-cflags-part-ii/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What are Snapshots?</title>
		<link>http://www.alunduil.com/2011/02/15/what-are-snapshots/</link>
		<comments>http://www.alunduil.com/2011/02/15/what-are-snapshots/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 22:41:27 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[disk]]></category>
		<category><![CDATA[lvm]]></category>
		<category><![CDATA[snapshots]]></category>
		<category><![CDATA[virtualbox]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=373</guid>
		<description><![CDATA[Introduction It seems that disk snapshots have become a hot topic and a confusing topic.  I intend to simply outline what snapshots look like in terms of the lower layers of abstraction and nothing more.  Snapshots are built into things like LVM, SAN, etc but I will not be covering those technologies.  Instead, what I <a href='http://www.alunduil.com/2011/02/15/what-are-snapshots/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>It seems that disk snapshots have become a hot topic and a confusing topic.  I intend to simply outline what snapshots look like in terms of the lower layers of abstraction and nothing more.  Snapshots are built into things like LVM, SAN, etc but I will not be covering those technologies.  Instead, what I intend to cover is the abstractions ranging from the disk device to the snapshot.</p>
<h1>The Disk</h1>
<p>A hard disk is typically chopped up into pieces called partitions (and this is the unit I&#8217;ll use as my foundation).  These logical separations of the blocks on a disk allow us to make sure that disks are not over-allocated for one particular purpose or lose access to a system if one partition fills up, etc.  Partitioning is only the beginning.   We are able to take the idea of partitions and extend the idea of a contiguous region of blocks to the strange concept of snapshots as well.</p>
<h1>Writing to Disk</h1>
<p>Using our simplified view of a disk (a contiguous region of blocks) we can see that the simplest way to write data (ignoring filesystems) is to simply take our data one block at a time and place it on the disk.  This is great until we need to remove blocks or update blocks (which is probably why we only use this type of writing for tapes).  We&#8217;ll have to add some logic to this view of disks to handle the complexities of files but for all intensive purposes, disks are simply groups of blocks available for writing and groups of blocks that are already used.  If we want a consistent view of the data at any point it&#8217;s simply a matter of making sure nothing is writing to the disk (partition) we&#8217;re interested in.  This is where snapshots can help us out.</p>
<h1>Snapshots</h1>
<p>A snapshot creates another region of blocks we can write to.  Let me start that again &#8230; when you create a snapshot of some disk (snapshots are not standalone by any means) the following happens:</p>
<ul>
<li>It reserves space for a changelog (or writes that would happen to the disk) in the difference disk</li>
<li>It creates a new way to access the original disk via the snapshot name (which refers to the base disk)</li>
<li>It begins sending all writes to the reserved space for the changelog (depicted in the figure below)</li>
</ul>
<p>Thus, we have the following situation on the disk (again very simplified):</p>
<p><a href="http://www.alunduil.com/wp-content/uploads/2011/02/snapshots.png"><img class="aligncenter size-medium wp-image-375" title="snapshots" src="http://www.alunduil.com/wp-content/uploads/2011/02/snapshots-300x145.png" alt="" width="300" height="145" /></a></p>
<h1>Deleting Snapshots</h1>
<p>Since a snapshot isn&#8217;t a true partition what happens when one of these gets removed?  The obvious is that the snapshot name gets removed so it&#8217;s no longer accessible, but that&#8217;s not going to help rectify the two regions of data we now have on the disk.  This is handled by making the difference disk a literal list of differences.  I find it best to think of it (even though it may not actually be implemented in this fashion) as a queue of block changes or a transaction log for writes to the disk.  With this visualization of the process it makes sense as to what happens when the snapshot is removed:</p>
<ul>
<li>The reference to the base disk is removed</li>
<li>The difference disk is replayed onto the base disk (applying all recorded changes)</li>
</ul>
<p>That&#8217;s all there is to it.  Everything continues as if the snapshot exists until it has been fully replayed and then disk access resumes as normal without the snapshot.</p>
<h1>Conclusion</h1>
<p>Snapshots provide a convenient way to access a frozen image of a disk which is perfect for backups or point in time restores of data.  This is typically used via LVM, virtualbox, SANs, etc and has far-reaching impacts that allow system administration to be easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/15/what-are-snapshots/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Backing up PostgreSQL with Holland</title>
		<link>http://www.alunduil.com/2011/02/02/backing-up-postgresql-with-holland/</link>
		<comments>http://www.alunduil.com/2011/02/02/backing-up-postgresql-with-holland/#comments</comments>
		<pubDate>Thu, 03 Feb 2011 01:10:40 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[backups]]></category>
		<category><![CDATA[bacula]]></category>
		<category><![CDATA[holland]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[sqlite]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=294</guid>
		<description><![CDATA[Introduction Backups are a subject I return to semi-frequently with a passion to never be in an &#8220;oh shit&#8221; scenario.  Last time I built my backup system, bacula with a postgresql DB backend, I determined that I would move to a common database backup script for all of my databases.  Holland fit this bill perfectly <a href='http://www.alunduil.com/2011/02/02/backing-up-postgresql-with-holland/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Backups are a subject I return to semi-frequently with a passion to never be in an &#8220;oh shit&#8221; scenario.  Last time I built my backup system, bacula with a postgresql DB backend, I determined that I would move to a common database backup script for all of my databases.  Holland fit this bill perfectly with support for postgres, sqlite and mysql.  This allows one command to backup all of my databases on all of my servers and subsequently creates a much simpler bacula configuration (the database job is defined the same as the catalog job).</p>
<h1>The Solution</h1>
<p>The problem I had when configuring holland to backup postgresql is that there was no example configuration file.  It wasn&#8217;t hard to craft a working default postgres configuration and the following is what I came up with (/etc/holland/backupsets/default.conf:</p>
<pre>[holland:backup]
plugin = pgdump
backups-to-keep = 1
auto-purge-failures = yes
purge-policy = after-backup
estimated-size-factor = 1.0

[pgdump]
role = postgres

[pgauth]
username = postgres</pre>
<h1>Conclusion</h1>
<p>Setting up holland to backup databases is incredibly easy and flexible.  By having a common backup solution for all databases other configurations become easier and processes can be streamlined.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/02/02/backing-up-postgresql-with-holland/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Special Keys in zsh</title>
		<link>http://www.alunduil.com/2011/01/27/special-keys-in-zsh/</link>
		<comments>http://www.alunduil.com/2011/01/27/special-keys-in-zsh/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 02:26:40 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[bindkey]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[end]]></category>
		<category><![CDATA[home]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[zsh]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=288</guid>
		<description><![CDATA[I recently made the plunge and began using zsh in lieu of bash.  I&#8217;ve not regretted the decision in the slightest but there have been minor annoyances that needed to be dealt with.  The simplest annoyance was the special keys (delete, home, page up, page down, etc).  The solution was quite simple and elegant but not completely <a href='http://www.alunduil.com/2011/01/27/special-keys-in-zsh/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I recently made the plunge and began using zsh in lieu of bash.  I&#8217;ve not regretted the decision in the slightest but there have been minor annoyances that needed to be dealt with.  The simplest annoyance was the special keys (delete, home, page up, page down, etc).  The solution was quite simple and elegant but not completely obvious.</p>
<p>The bindings usually are read from the file `/etc/inputrc`by bash but zsh does not do this by default.  There are probably more elegant solutions but a quick brute force solution is to create a bindkeys file out of inputrc:</p>
<pre>gawk '$1 ~ /.*:/ { print "bindkey",$1,$2 }' /etc/inputrc | \
sed -e 's/://g' &gt; ~/.zshrc-bindkeys</pre>
<p>Once this file has been crafted it&#8217;s simply a matter of invoking it from your .zshrc with `source ~/.zshrc-bindkeys`.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/01/27/special-keys-in-zsh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mailing Portage Output</title>
		<link>http://www.alunduil.com/2011/01/18/mailing-portage-output/</link>
		<comments>http://www.alunduil.com/2011/01/18/mailing-portage-output/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 23:49:06 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[emerge]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[logging]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[portage]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=282</guid>
		<description><![CDATA[Introduction Portage is an amazingly simple and complex piece of technology.  The simplicity in each piece&#8217;s ability to do a specific function comes together in a complex package management system that rivals all other forms of package management (at least in my opinion).  Automating updates is something that admins everywhere do out of necessity.  Heck, <a href='http://www.alunduil.com/2011/01/18/mailing-portage-output/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>Portage is an amazingly simple and complex piece of technology.  The simplicity in each piece&#8217;s ability to do a specific function comes together in a complex package management system that rivals all other forms of package management (at least in my opinion).  Automating updates is something that admins everywhere do out of necessity.  Heck, automating everything is an admin&#8217;s life.  Automating portage&#8217;s updates is a bit more harrowing than other package management systems but it isn&#8217;t impossible.</p>
<h1>Problem</h1>
<p>As admins we attempt to simplify the work we actually do by writing scripts and programs to do most of our job for us.  It&#8217;s often been said that systems admins are the only people whose job description is to remove their job responsibilities.</p>
<p>Portage doesn&#8217;t have any default automation for doing nightly or even weekly portage updates but that doesn&#8217;t stop the creative from coming up with their own solution.  A simple but elegant solution is to create a small cron script that runs every day.  The problem comes when you want to read the wonderful output of portage (sometimes these messages can guide you when problems are about to occur) to avert disasters.  If the updates are performed from cron, the output will be preserved in an e-mail to the appropriate user but then we have to sift through all of the output at once.  This also doesn&#8217;t solve the issue if the updates are performed by another utility such as puppet.  These annoying little changes to the problem require a slightly more elegant solution.</p>
<h1>Solution</h1>
<p>The solution is to take advantage of portage&#8217;s logging specifications.  From the make.conf man file:</p>
<ul>
<li>﻿﻿PORTAGE_ELOG_CLASSES</li>
<li>PORTAGE_ELOG_SYSTEM</li>
<li>PORTAGE_ELOG_COMMAND</li>
<li>PORTAGE_ELOG_MAILURI</li>
<li>PORTAGE_ELOG_MAILFROM</li>
<li>PORTAGE_ELOG_MAILSUBJECT</li>
</ul>
<p>Using a combination of these directives in the make.conf file allows us to log the reports from portage to a large number of locations.  If we wanted to simply add mailing output (not the full build output just the messages) we would add the following directives to make.conf:</p>
<pre>PORTAGE_ELOG_SYSTEM="save mail"
PORTAGE_ELOG_MAILFROM="portage@alunduil.com"</pre>
<p>This simply adds the mailing log utility to portage and specifies that the e-mails come from the address portage@alunduil.com.  Of course, much more complex configurations can be crafted to suit any admins&#8217; needs.</p>
<h1>Conclusion</h1>
<p>Letting your servers notify you of possible actions is one way of automating maintenance tasks; making maintenance eventually disappear from your task list. By starting with the tasks that are repeated the most frequently, you can quickly free up time for higher level automation and organization which leads to a cleaner and sturdier infrastructure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2011/01/18/mailing-portage-output/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pclean, a new /etc/portage/package.* cleaner</title>
		<link>http://www.alunduil.com/2010/11/07/pclean-a-new-etcportagepackage-cleaner/</link>
		<comments>http://www.alunduil.com/2010/11/07/pclean-a-new-etcportagepackage-cleaner/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 15:53:34 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[layman]]></category>
		<category><![CDATA[overlay]]></category>
		<category><![CDATA[pclean]]></category>
		<category><![CDATA[portage]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=245</guid>
		<description><![CDATA[I&#8217;ve often gotten frustrated with my /etc/portage/package.* files when they become massive and full of crud that I don&#8217;t even have installed any longer. Because of this I have crafted a simple little utility to clean out packages that are no longer installed and use flags that are no longer valid from these files. This <a href='http://www.alunduil.com/2010/11/07/pclean-a-new-etcportagepackage-cleaner/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve often gotten frustrated with my /etc/portage/package.* files when they become massive and full of crud that I don&#8217;t even have installed any longer.  Because of this I have crafted a simple little utility to clean out packages that are no longer installed and use flags that are no longer valid from these files.  This should help trim the cruft from the Gentoo configuration.</p>
<p>The utility, <a href="http://www.alunduil.com/programs/pclean/">pclean</a>, does all of this and only has one major problem (so far) before I shall call it good enough for a 1.0 release.  If you would like to try this little utility; it&#8217;s available in <a href="http://www.alunduil.com/alunduil-overlay/">my overlay</a> and if you notice any odd behavior please report it to <a href="https://bugzilla.alunduil.com/buglist.cgi?cmdtype=runnamed&amp;namedcmd=Pclean">my bugzilla</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/11/07/pclean-a-new-etcportagepackage-cleaner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cacti Ping NaN With iputils-20100418</title>
		<link>http://www.alunduil.com/2010/10/24/cacti-ping-nan-with-iputils-20100418/</link>
		<comments>http://www.alunduil.com/2010/10/24/cacti-ping-nan-with-iputils-20100418/#comments</comments>
		<pubDate>Sun, 24 Oct 2010 23:28:10 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[cacti]]></category>
		<category><![CDATA[iptuils]]></category>
		<category><![CDATA[nan]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[ping]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=221</guid>
		<description><![CDATA[Introduction It appears the output of ping has changed in this release of iputils from referring to the icmp sequence numbers as icmp_seq to icmp_req which obliterates the ping.pl script that cacti uses to do pings of servers it watches. The Fix The fix is quite simple: change the seq to req in the grep <a href='http://www.alunduil.com/2010/10/24/cacti-ping-nan-with-iputils-20100418/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>It appears the output of ping has changed in this release of iputils from referring to the icmp sequence numbers as icmp_seq to icmp_req which obliterates the ping.pl script that cacti uses to do pings of servers it watches.</p>
<h1>The Fix</h1>
<p>The fix is quite simple:  change the seq to req in the grep line of ping.pl but the following fix is probably more versatile (and will be checked for upstream).</p>
<pre>*** ping.pl     2010-07-09 17:33:46.000000000 -0500
--- ping.pl.new 2010-10-24 18:22:16.325881546 -0500
***************
*** 4,10 ****
  $host = $ARGV[0];
  $host =~ s/tcp:/$1/gis;

! open(PROCESS, "ping -c 1 $host | grep icmp_seq | grep time |");
  $ping = ;
  close(PROCESS);
  $ping =~ m/(.*time=)(.*) (ms|usec)/;
--- 4,10 ----
  $host = $ARGV[0];
  $host =~ s/tcp:/$1/gis;

! open(PROCESS, "ping -c 1 $host | grep -E icmp_\(r\|s\)eq | grep time |");
  $ping = ;
  close(PROCESS);
  $ping =~ m/(.*time=)(.*) (ms|usec)/;</pre>
<h1>Conclusion</h1>
<p>Sometimes things break just because of small changes.  This is a simple example of that and the quick fix for the annoyance of not recording your ping times.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/10/24/cacti-ping-nan-with-iputils-20100418/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hamachi on Gentoo</title>
		<link>http://www.alunduil.com/2010/09/27/hamachi-on-gentoo/</link>
		<comments>http://www.alunduil.com/2010/09/27/hamachi-on-gentoo/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 21:11:12 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[gentoo]]></category>
		<category><![CDATA[hamachi]]></category>
		<category><![CDATA[openvpn]]></category>
		<category><![CDATA[VPN]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=217</guid>
		<description><![CDATA[Introduction Hamachi is a lightweight personal VPN connector that is a breeze to setup but there can be some pain if you don&#8217;t know what to expect. As always Gentoo provides us with an ebuild that simplifies the installation process but getting up and running is still a little confusing. Installation and Setup User Specific <a href='http://www.alunduil.com/2010/09/27/hamachi-on-gentoo/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p><a href="https://secure.logmein.com/products/hamachi2/">Hamachi</a> is a lightweight personal VPN connector that is a breeze to setup but there can be some pain if you don&#8217;t know what to expect.  As always Gentoo provides us with an ebuild that simplifies the installation process but getting up and running is still a little confusing.</p>
<h1>Installation and Setup</h1>
<h2>User Specific Configurations</h2>
<p>The obvious first step is `emerge -av hamachi` (this only available to ~arch right now so add to `package.keywords` as necessary).  The following are the typical instructions to install hamachi on Gentoo from portage:</p>
<ol>
<li>Add to `packages.keywords` if necessary</li>
<li>`emerge -av hamachi`</li>
<li>`rc-update add tuncfg default`</li>
</ol>
<p>After these steps have been taken you can run hamachi as any user on the system for ad-hoc VPN creation.</p>
<h2>Server Wide Configuration</h2>
<p>If you prefer to do a system wide on boot VPN with hamachi this is also possible but requires a slightly different setup:</p>
<ol>
<li>Add to `packages.keywords` if necessary</li>
<li>`emerge -av hamachi`</li>
<li>rc-update add hamachi default</li>
</ol>
<p>Now all configuration should be placed inside `/etc/hamachi` for this setup so the system will automatically start routing traffic correctly.</p>
<h1>Kernel Configuration</h1>
<p>For hamachi to work correctly you do need the tun parameter in your kernel or loaded as a module.  This parameter is located in Device Drivers-&gt;Network device support-&gt;Universal TUN/TAP device driver support.</p>
<h1>Using Hamachi</h1>
<p>Now that hamachi is on the system we need to start using it.  The server-wide installation doesn&#8217;t require this (but I&#8217;m sure you can use this method to create a configuration usable by the server-wide instance) but the user specific usage does.</p>
<p>Starting hamachi is as simple as the following:</p>
<ol>
<li>`hamachi-init`</li>
<li>`hamachi start`</li>
<li>`hamachi login`</li>
<li>`hamachi create  [ ]`</li>
<li>`hamachi join  [ ]`</li>
<li>`hamachi go-online `</li>
</ol>
<p>That&#8217;s it.  You&#8217;re now connected to a private network named .  You can view who else is connected to your network with `hamachi list` and `hamachi get-nicks`.</p>
<h1>Conclusion</h1>
<p>Setting up a VPN can be daunting (see the OpenVPN configuration documentation) or it can be a breeze with hamachi.  Need a quick VPN for LAN gaming or a VPN for performing maintenance over the internet on a device behind a firewall?  Hamachi may be the quick solution you&#8217;re looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/09/27/hamachi-on-gentoo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bind Mount and Uses to Avoid</title>
		<link>http://www.alunduil.com/2010/09/19/bind-mount-and-uses-to-avoid/</link>
		<comments>http://www.alunduil.com/2010/09/19/bind-mount-and-uses-to-avoid/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 00:55:50 +0000</pubDate>
		<dc:creator>Alex Brandt</dc:creator>
				<category><![CDATA[Linux Guides]]></category>
		<category><![CDATA[autochroot]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[chroot]]></category>
		<category><![CDATA[jail]]></category>
		<category><![CDATA[mount]]></category>

		<guid isPermaLink="false">http://www.alunduil.com/?p=211</guid>
		<description><![CDATA[Introduction Not overly recently, I was asked to configure a chroot jail by setting up bind mounts instead of copying over the correct binaries. The incident caused a really interesting system failure, a wake-up call to myself, and an ambitious project to create an autochroot command (more later). The Back Story When setting up a <a href='http://www.alunduil.com/2010/09/19/bind-mount-and-uses-to-avoid/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<h1><strong>Introduction</strong></h1>
<p><strong></strong>Not overly recently, I was asked to configure a chroot jail by setting up bind mounts instead of copying over the correct binaries.  The incident caused a really interesting system failure, a wake-up call to myself, and an ambitious project to create an autochroot command (more later).</p>
<h1><strong>The Back Story</strong></h1>
<p>When setting up a chroot jail it&#8217;s well known that all the binaries and references that will be used in that jail need to be inside that jail.  This creates quite a complicated configuration for something even as simple as creating a chroot jail that only has bash and bash internals in it.  Not only do we need to create a clean directory structure and duplicate our file system hierarchy but we also need to create all the dependencies (and for bash this quickly grows):</p>
<p>ldd /bin/bash<br />
linux-vdso.so.1 =&gt;  (0x00007fff189ff000)<br />
libncurses.so.5 =&gt; /lib/libncurses.so.5 (0x00007f6ca8604000)<br />
libdl.so.2 =&gt; /lib/libdl.so.2 (0x00007f6ca8400000)<br />
libc.so.6 =&gt; /lib/libc.so.6 (0x00007f6ca809a000)<br />
/lib64/ld-linux-x86-64.so.2 (0x00007f6ca8854000)</p>
<p>Once all the dependencies are in place, the proper items to do work in this minimal shell environment also need to be installed.  This may include device nodes or system environment files (e.g. /etc/passwd, /etc/shadow).  Which make some commands a real pain to install in a chroot by hand (e.g. /usr/bin/ssh, /usr/bin/scp, etc).</p>
<h1><strong>The Problem</strong></h1>
<p>So, it&#8217;s hard; that&#8217;s not a big deal.  There are ways to make this easier.  Things like bind mounts:</p>
<p>mount -o bind</p>
<p>These handy features allow you to take any directory in the system and mount it somewhere else.  These become extremely useful when setting up a chroot environment for system recovery via a livecd but can be a ticking time bomb if used incorrectly.</p>
<p>Alright, let&#8217;s solve our chroot problem with bind mounts, but I bet you can guess by this point how it&#8217;s going to be accomplished.  We&#8217;re simply going to mount all of the necessary areas of the external filesystem inside the chroot:</p>
<p>mount -o bind /dev /chroot/dev<br />
mount -o bind /lib /chroot/lib<br />
mount -o bind /usr/lib /chroot/usr/lib</p>
<p>Now, that chroot was much easier to set up and work with, but what happens if an unsuspecting party does the unthinkable: `rm -fr /chroot`.  They&#8217;re simply cleaning up a chroot environment that doesn&#8217;t need to be used anymore, right?  Unfortunately, that&#8217;s not the case.  This will remove all files in /chroot including /dev, /lib, /usr/lib, etc.</p>
<h1><strong>The Lesson</strong></h1>
<p>Don&#8217;t ever use bind mounts in chroot environments unless you know exactly what you are doing!  Even then, it may be best practice to simply not use bind mounts.  You may be thinking, why can&#8217;t we simply mount these points readonly?  Unfortunately, bind mounts aren&#8217;t that smart.  This is what happens when you attempt a bind mount readonly:</p>
<p>mount -o bind,or /proc /mnt<br />
mount: warning: /mnt seems to be mounted read-write.<br />
mount<br />
/proc on /mnt type none (rw,bind)</p>
<p>Not quite what we were looking for and unfortunate for our quick solution.</p>
<h1><strong>Conclusion</strong></h1>
<p>Never use bind mounts for a chroot environment (except maybe livecd chroot environments).  It may take more time but copying the necessary binaries to the chroot is much safer and will keep your system from any inadvertent harm.</p>
<p>Now, I mentioned that I came up with a much more ambitious solution to this problem, <a href="http://github.com/alunduil/autochroot">autoroot</a>.  This small utility (when finished) will be able to take a directory and list of binaries and automatically create an appropriate chroot environment.  The system should be smart enough to take into consideration different distributions and installation points (a current limitation of existing solutions).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.alunduil.com/2010/09/19/bind-mount-and-uses-to-avoid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached (User agent is rejected)
Database Caching 5/22 queries in 0.027 seconds using memcached
Object Caching 686/733 objects using memcached

Served from: www.alunduil.com @ 2012-02-06 09:54:19 -->
