<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[The Wizard's Lab]]></title>
  <link href="http://dont-panic.org//atom.xml" rel="self"/>
  <link href="http://dont-panic.org//"/>
  <updated>2012-03-05T10:20:08+01:00</updated>
  <id>http://dont-panic.org//</id>
  <author>
    <name><![CDATA[Ingo Hofmann]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Slow SSH Connection Establishment]]></title>
    <link href="http://dont-panic.org//blog/2012/03/05/slow-ssh-connection-establishment/"/>
    <updated>2012-03-05T10:09:00+01:00</updated>
    <id>http://dont-panic.org//blog/2012/03/05/slow-ssh-connection-establishment</id>
    <content type="html"><![CDATA[<p>I recently noticed a particular SSH connection being painfully slow during the login phase.</p>

<!-- more -->


<p>At the time I was working from home, using a VPN tunnel to the office, connected to a Telekom V-DSL with a buggy Speedport Router. Hence my first suspect was a DNS issue and, indeed, the setps descibed <a href="http://maestric.com/doc/mac/fix_ssh_connection_delays">here</a> fixed the problem.</p>

<p>Anyone familiar with my recent Telekom issues understands why DNS was the obvious pick (there might be a comprehensive rant about that subject if I ever feel like talking about that experience).</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Running portsnap from cron]]></title>
    <link href="http://dont-panic.org//blog/2012/01/24/running-portsnap-from-cron/"/>
    <updated>2012-01-24T20:44:00+01:00</updated>
    <id>http://dont-panic.org//blog/2012/01/24/running-portsnap-from-cron</id>
    <content type="html"><![CDATA[<p>Today I wanted to polish up my backup scripts by automatically updating the installed ports and sending me a mail in case one of the installed packages is older than its port (FYI: this is what <code>pkg_version -v</code> is for). My first approach was to have something like this in a single python script:</p>

<!-- more -->




<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="kn">import</span> <span class="nn">os</span><span class="o">,</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">subprocess</span>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">check_version</span> <span class="p">(</span><span class="n">output</span><span class="p">):</span>
</span><span class='line'>    <span class="n">packages</span> <span class="o">=</span> <span class="n">output</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span>
</span><span class='line'>    <span class="c"># get rid of the suspicious additional last element (a single &quot;\n&quot;)</span>
</span><span class='line'>    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">packages</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
</span><span class='line'>        <span class="n">info</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
</span><span class='line'>        <span class="k">if</span> <span class="n">info</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;&lt;&quot;</span><span class="p">:</span>
</span><span class='line'>            <span class="c"># cron will take care of sending the mail from here</span>
</span><span class='line'>            <span class="k">print</span> <span class="n">p</span>
</span><span class='line'>
</span><span class='line'><span class="n">null</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">devnull</span><span class="p">)</span>
</span><span class='line'><span class="k">try</span><span class="p">:</span>
</span><span class='line'>    <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="s">&quot;portsnap&quot;</span><span class="p">,</span> <span class="s">&quot;fetch&quot;</span><span class="p">],</span> <span class="n">stdout</span><span class="o">=</span><span class="n">null</span><span class="p">)</span>
</span><span class='line'>    <span class="n">subprocess</span><span class="o">.</span><span class="n">check_call</span><span class="p">([</span><span class="s">&quot;portsnap&quot;</span><span class="p">,</span> <span class="s">&quot;update&quot;</span><span class="p">],</span> <span class="n">stdout</span><span class="o">=</span><span class="n">null</span><span class="p">)</span>
</span><span class='line'>    <span class="n">check_version</span><span class="p">(</span><span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">([</span><span class="s">&quot;pkg_version&quot;</span><span class="p">,</span> <span class="s">&quot;-v&quot;</span><span class="p">]))</span>
</span><span class='line'><span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
</span><span class='line'>    <span class="k">print</span> <span class="s">&quot;*** ERROR ***&quot;</span>
</span><span class='line'>    <span class="k">print</span> <span class="n">e</span><span class="o">.</span><span class="n">output</span>
</span><span class='line'><span class="n">null</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
</span></code></pre></td></tr></table></div></figure>


<p>Which always returned <em>none</em> although I was sure there was an outdated package installed on the system, plus the script worked perfectly when run interactively (not from <em>cron</em>). After fiddling around a lot with environment and path settings in <em>crontab</em>, I decided to get the actual output of the 2 portsnap commands. This eventually provided the clue &#8230; <em>portsnap fetch</em> is not supossed to be run from cron and <strong>actually checks for that!</strong> A quick look in the according man page revealed the secret:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="err">$</span> <span class="n">portsnap</span> <span class="n">cron</span>
</span></code></pre></td></tr></table></div></figure>


<p>which waits between 1 and 60 minutes before actually fetching the updates. So the final solution is now broken down in two parts (providing even basic privilege separation).</p>

<p>A crontab entry (root):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="mi">0</span> <span class="mi">1</span> <span class="o">*</span> <span class="o">*</span> <span class="o">*</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">sbin</span><span class="o">/</span><span class="n">portsnap</span> <span class="n">cron</span> <span class="o">&gt;</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">null</span> <span class="o">&amp;&amp;</span> <span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">sbin</span><span class="o">/</span><span class="n">portsnap</span> <span class="n">update</span> <span class="o">&gt;</span> <span class="o">/</span><span class="n">dev</span><span class="o">/</span><span class="n">null</span>
</span></code></pre></td></tr></table></div></figure>


<p>and a checker script (user):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
</pre></td><td class='code'><pre><code class='python'><span class='line'><span class="kn">import</span> <span class="nn">subprocess</span>
</span><span class='line'>
</span><span class='line'><span class="k">def</span> <span class="nf">check_version</span> <span class="p">(</span><span class="n">output</span><span class="p">):</span>
</span><span class='line'>    <span class="sd">&quot;&quot;&quot;</span>
</span><span class='line'><span class="sd">    checks the output of &#39;pkg_version -v&#39; for outdated packages</span>
</span><span class='line'><span class="sd">    &quot;&quot;&quot;</span>
</span><span class='line'>    <span class="n">packages</span> <span class="o">=</span> <span class="n">output</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span>
</span><span class='line'>    <span class="c"># get rid of the suspicious additional last element (a single &quot;\n&quot;)</span>
</span><span class='line'>    <span class="k">for</span> <span class="n">p</span> <span class="ow">in</span> <span class="n">packages</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]:</span>
</span><span class='line'>        <span class="n">info</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>
</span><span class='line'>        <span class="k">if</span> <span class="n">info</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;&lt;&quot;</span><span class="p">:</span>
</span><span class='line'>            <span class="c"># cron will take care of sending the mail from here</span>
</span><span class='line'>            <span class="k">print</span> <span class="n">p</span>
</span><span class='line'>
</span><span class='line'><span class="k">try</span><span class="p">:</span>
</span><span class='line'>    <span class="n">check_version</span><span class="p">(</span><span class="n">subprocess</span><span class="o">.</span><span class="n">check_output</span><span class="p">([</span><span class="s">&quot;pkg_version&quot;</span><span class="p">,</span> <span class="s">&quot;-v&quot;</span><span class="p">]))</span>
</span><span class='line'><span class="k">except</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">CalledProcessError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
</span><span class='line'>    <span class="k">print</span> <span class="s">&quot;*** ERROR ***&quot;</span>
</span><span class='line'>    <span class="k">print</span> <span class="n">e</span><span class="o">.</span><span class="n">output</span>
</span></code></pre></td></tr></table></div></figure>


<p>In my opinion a classical case of <strong>RTFM</strong> &#8230; and yes, I know, all of the above can be condensed and my exception handler is exceptionally bad.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[There and Back Again ...]]></title>
    <link href="http://dont-panic.org//blog/2012/01/20/there-and-back-again-dot-dot-dot/"/>
    <updated>2012-01-20T08:20:00+01:00</updated>
    <id>http://dont-panic.org//blog/2012/01/20/there-and-back-again-dot-dot-dot</id>
    <content type="html"><![CDATA[<p>&#8220;Seriously? Again?&#8221; - &#8220;Hell yea, it was about time &#8230;&#8221;.</p>

<p>The Ubuntu Server distribution that has been running this server broke &#8230; again. Only a couple of months after I did a clean install, I dared to upgrade the system from 11.04 to 11.10, or at least I tried &#8230;</p>

<!-- more -->


<p>&#8230; unfortunately the machine turned out to be unreachable after the upgrade. So I had to <strong>physically</strong> log into my server just to find out the network was down, although the configuration didn&#8217;t change during the upgrade. A little debugging and a couple of reboots later, the network still wouldn&#8217;t start automatically - yet another incident in a series of Linux fails over the last year or so. Kubuntu desktop starts shipping version 4 and by that turns unusable. After switching to Ubuntu (and thereby Gnome), I had a sort-of working desktop system for a couple of months (I never liked Gnome, but it seriously was the better choice at the time). Then Ubuntu decides to drop Gnome in favour of something called &#8220;Unity&#8221;. An intersting approach, maybe a great choice on a netbook, but nothing more than a study on desktop concepts. After trying  differnt flavours of Linux Mint and re-checking the current status of Kubuntu I&#8217;m now stuck with a broken Ubuntu for my Linux work, a Linux that is good enough to sshfs to my projects and do the actual desktop work on my MacBook.</p>

<p>Equipped with a great deal of frustration, not so much about the Linux kernel but the crappy userland and bad decisions made by distributors, I decided to step back a couple of years and install FreeBSD. Back in the days as a student I fiddled around with a couple of BSD flavours and had, among other things, an OpenBSD firewall and a FreeBSD file server. Eventually I decided against BSD back then, because I was experimenting with those systems a lot, mainly installing and uninstalling packages the whole day. This is something the ports collection, BSD&#8217;s preferred way of dealing with software packages, is not exactly helpful with. On the other hand, now I was looking for something well defined with as little maintenance as possible, so FreeBSD seemed like a natural choice.</p>

<p>The current system is running:</p>

<ul>
<li><a href="http://www.freebsd.org/releases/8.2R/announce.html">FreeBSD 8.2-RELEASE</a></li>
<li><a href="http://www.lighttpd.net/">lighttpd</a></li>
<li><a href="http://octopress.org/">Octopress</a></li>
<li>No MySQL (PostgreSQL, &#8230;)</li>
<li>No PHP</li>
</ul>


<p>And here&#8217;s a list of things I like about the new setup:</p>

<ul>
<li>Installation of a base system leaves with just that, a base systems</li>
<li>Output of <em>ps aux</em> fits on a single screen (including 8 lines <em>getty</em>)</li>
<li>Output of <em>netstat</em> fits on a single screen</li>
<li>Config files are where the package&#8217;s documentation claims they are</li>
<li>Searching the web for a technical issues turns up actual results (not 30+ hits to forums filled with people complaining about their Linux not behaving like Windows)</li>
<li>Updating the systems doesn&#8217;t require a reboot twice a week because a new kernel shipped</li>
<li>many more little details that just make me happy :-)</li>
</ul>


<p><img src="http://www.freebsd.org/gifs/banner1.gif"></p>
]]></content>
  </entry>
  
</feed>

