<?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>Lennart&#039;s weblog &#187; Linux</title>
	<atom:link href="http://blog.karssen.org/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.karssen.org</link>
	<description>Open source, computers, Africa and other more (or less) interesting stuff.</description>
	<lastBuildDate>Thu, 02 Feb 2012 19:15:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Using Plugwise adapters with Linux</title>
		<link>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/</link>
		<comments>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 20:53:08 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=214</guid>
		<description><![CDATA[Yesterday I received a small package I had ordered: the Plugwise Home Start kit. According to the box it is an energy management and control system. The idea is that you insert a sort of adaptor between a power socket and a device and using the Plugwise Source software you can monitor the power usage [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I received a small package I had ordered: the <a href="http://www.plugwise.com">Plugwise</a> <a href="http://www.plugwise.com/idplugtype-f/home-start">Home Start</a> kit. According to the box it is an energy management and control system. The idea is that you insert a sort of adaptor between a power socket and a device and using the Plugwise Source software you can monitor the power usage of the device. Furthermore, you can use the software to create schedule to turn the device on and off at a specific time.</p>
<p>The package contains the following:</p>
<ul>
<li>a USB adapter (called the Stick)</li>
<li>a Circle+, the master adaptor that keeps track of the other devices in the network
<li>a Circle, the regular members of the Plugwise network
</ul>
<p>The Circles communicate to each other using the ZigBee protocol in the 2.4GHz range. According to the documentation, the range of each Circle is about 5m.</p>
<p>Unfortunately the Source software only runs on windows. Luckily some people have already analysed the protocol and written some software to control the Plugwise devices (see links below).</p>
<h2>First steps</h2>
<p>  Plugging the USB dongle in gives the following output in <code>/var/log/syslog</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">Nov 19 12:20:37 barabas kernel: [  182.855742] usb 1-1.6.1.1.3: new full speed USB device number 14 using ehci_hcd
Nov 19 12:20:37 barabas mtp-probe: checking bus 1, device 14: &quot;/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.6/1-1.6.1/1-1.6.1.1/1-1.6.1.1.3&quot;
Nov 19 12:20:37 barabas mtp-probe: bus: 1, device: 14 was not an MTP device
Nov 19 12:20:37 barabas kernel: [  183.169370] usbcore: registered new interface driver usbserial
Nov 19 12:20:37 barabas kernel: [  183.169389] USB Serial support registered for generic
Nov 19 12:20:37 barabas kernel: [  183.169431] usbcore: registered new interface driver usbserial_generic
Nov 19 12:20:37 barabas kernel: [  183.169434] usbserial: USB Serial Driver core
Nov 19 12:20:37 barabas kernel: [  183.171310] USB Serial support registered for FTDI USB Serial Device
Nov 19 12:20:37 barabas kernel: [  183.171552] ftdi_sio 1-1.6.1.1.3:1.0: FTDI USB Serial Device converter detected
Nov 19 12:20:37 barabas kernel: [  183.171588] usb 1-1.6.1.1.3: Detected FT232RL
Nov 19 12:20:37 barabas kernel: [  183.171591] usb 1-1.6.1.1.3: Number of endpoints 2
Nov 19 12:20:37 barabas kernel: [  183.171595] usb 1-1.6.1.1.3: Endpoint 1 MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171598] usb 1-1.6.1.1.3: Endpoint 2 MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171602] usb 1-1.6.1.1.3: Setting MaxPacketSize 64
Nov 19 12:20:37 barabas kernel: [  183.171975] usb 1-1.6.1.1.3: FTDI USB Serial Device converter now attached to ttyUSB0
Nov 19 12:20:37 barabas kernel: [  183.171998] usbcore: registered new interface driver ftdi_sio
Nov 19 12:20:37 barabas kernel: [  183.172002] ftdi_sio: v1.6.0:USB FTDI Serial Converters Driver
Nov 19 12:20:37 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) opening serial port...
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) closing serial port...
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) serial port closed
Nov 19 12:20:49 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) opening serial port...
Nov 19 12:20:55 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) closing serial port...
Nov 19 12:20:55 barabas modem-manager[901]: &lt;info&gt;  (ttyUSB0) serial port closed</pre></div></div>

<p><code>lsusb</code> gives:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">Bus 001 Device 014: ID 0403:6001 Future Technology Devices International, Ltd FT232 USB-Serial (UART) IC</pre></div></div>

<p>I couldn&#8217;t get the pairing to work under Linux (with the PlugwiseOnLinux scripts), Even though I corrected the MAC address in the python code. I then tried it in Windows where I failed at first also. After resetting the Circle+ and the Circle (removing/inserting them into the power outlet with 3 second intervals, as mentioned in the FAW on the plugwise website) I managed to pair the Circles. Looking back, I think I didn&#8217;t wait long enough for the pairing to work under Linux. During the trials in Windows I noticed that the pairing can take up to about 5 minutes&#8230;</p>
<p>Back in Linux I used python-plugwise (see links below) to turn the Circles on and off, e.g. this is how I turn my Circle+ off (note that I am a member of the dialout group, which is needed to communicate with <code>/dev/ttyUSB0</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ plugwise_util <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0 <span style="color: #660033;">-m</span> 000D6F0000B1C117 <span style="color: #660033;">-s</span> off</pre></div></div>

<p>This is what I want! The only minor downside of python-plugwise is that it depends on the crcmod python library, which apparently is not package for Debian/Ubuntu. So installing using the python-setup framework as mentioned in the README is necessary.</p>
<p>Reading out the current power usage of my Circle works also:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ plugwise_util <span style="color: #660033;">-d</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>ttyUSB0 <span style="color: #660033;">-m</span> 000D6F0000B85134 <span style="color: #660033;">-p</span>
power usage: 2.27W</pre></div></div>

<p>So, no that it works, what am I going to do with the Plugwise modules? I&#8217;m going to use them in my backup scripts to switch the power to my external hard drives.</p>
<h2> Making a .deb</h2>
<p>I used <code>checkinstall</code> to make a package of python-plugwise. In a working directory, first check out the source code of python-plugwise using mercurial, as mentioned on the web site:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ hg clone https:<span style="color: #000000; font-weight: bold;">//</span>bitbucket.org<span style="color: #000000; font-weight: bold;">/</span>hadara<span style="color: #000000; font-weight: bold;">/</span>python-plugwise</pre></div></div>

<p>Then run <code>checkinstall</code> and don&#8217;t forget to fill in the details correctly. For example, the package name is &#8216;python&#8217; by default, which you definitely don&#8217;t want, since that would overwrite Ubuntu&#8217;s default &#8216;python&#8217; package. Also make sure that you remove the crcmod python library if you installed python-plugwise before, otherwise it won&#8217;t get packaged. The output below shows the final values, after I changed them.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> checkinstall <span style="color: #660033;">-D</span> python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
&nbsp;
checkinstall 1.6.2, Copyright <span style="color: #000000;">2009</span> Felipe Eduardo Sanchez Diaz Duran
	      This software is released under the GNU GPL.
&nbsp;
&nbsp;
&nbsp;
<span style="color: #000000; font-weight: bold;">*****************************************</span>
<span style="color: #000000; font-weight: bold;">****</span> Debian package creation selected <span style="color: #000000; font-weight: bold;">***</span>
<span style="color: #000000; font-weight: bold;">*****************************************</span>
&nbsp;
This package will be built according to these values:
&nbsp;
<span style="color: #000000;">0</span> -  Maintainer: <span style="color: #7a0874; font-weight: bold;">&#91;</span> lennart<span style="color: #000000; font-weight: bold;">@</span>karssen.org <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">1</span> -  Summary: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise is used to control the Plugwise power switches <span style="color: #c20cb9; font-weight: bold;">as</span> well <span style="color: #c20cb9; font-weight: bold;">as</span> <span style="color: #c20cb9; font-weight: bold;">read</span> out information on power usage. <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">2</span> -  Name:    <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">3</span> -  Version: <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">0.2</span>-hg-<span style="color: #000000;">20111120</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">4</span> -  Release: <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">5</span> -  License: <span style="color: #7a0874; font-weight: bold;">&#91;</span> GPL <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">6</span> -  Group:   <span style="color: #7a0874; font-weight: bold;">&#91;</span> checkinstall <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">7</span> -  Architecture: <span style="color: #7a0874; font-weight: bold;">&#91;</span> amd64 <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">8</span> -  Source location: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">9</span> -  Alternate <span style="color: #7a0874; font-weight: bold;">source</span> location: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">10</span> - Requires: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">11</span> - Provides: <span style="color: #7a0874; font-weight: bold;">&#91;</span> python-plugwise <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">12</span> - Conflicts: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000;">13</span> - Replaces: <span style="color: #7a0874; font-weight: bold;">&#91;</span>  <span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
Enter a number to change any of them or press ENTER to <span style="color: #7a0874; font-weight: bold;">continue</span>:</pre></div></div>

<p>You can check the contents of the package to make sure the crcmod<br />
files are included using <code>dpkg</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">--contents</span> python-plugwise_0.2-hg-<span style="color: #000000;">20111120</span>-<span style="color: #000000;">1</span>_amd64.deb</pre></div></div>

<p>An idea for later: make an SNMP module that calls <i>plugwise_util</i> to get the power usage so that I can monitor the power usage of a device using Cacti.</p>
<h2>Links</h2>
<ul>
<li>The software I use: <a href="https://bitbucket.org/hadara/python-plugwise/overview">python-plugwise</a></li>
<li><a href="http://www.maartendamen.com/tag/plugwise/">The blog of Maarten Damen</a>, the guy that seems to have been the first one to analyse the plugwise protocol</li>
<li><a href="http://roheve.wordpress.com/tag/plugwise/">Another blog, also with info on the protocol</a></li>
<li><a href="https://github.com/hackstuces/PlugwiseOnLinux.git">PlugwiseOnLinux</a>, a set of python scripts for pairing Plugwise and the Circles. Did not work with me at first, didn&#8217;t retry later</li>
<li><a href="http://wordpress.dirkengels.com/tag/plugweb-2/">PlugWeb</a>, a PHP interface, for those wanting to control their Plugwise network via a web interface</li>
<li>According to its website <a href="http://www.domotiga.nl/">DomotiGa</a> can also control Plugwise devices, but I haven&#8217;t tried it (yet)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/11/20/using-plugwise-adapters-with-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Loggerhead behind Apache on Ubuntu 11.04</title>
		<link>http://blog.karssen.org/2011/08/22/installing-loggerhead-behind-apache-on-ubuntu-11-04/</link>
		<comments>http://blog.karssen.org/2011/08/22/installing-loggerhead-behind-apache-on-ubuntu-11-04/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 22:29:52 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=163</guid>
		<description><![CDATA[Introduction Loggerhead is a webfrontend for Bazaar (usually abbreviated as bzr) repositories. Bazaar is a so-called distributed version control system. So, if you have one or more bzr repositories you can use Loggerhead to look at the files, read the change logs and see the differences between revisions from within your web browser. The main [...]]]></description>
			<content:encoded><![CDATA[<h2>Introduction</h2>
<p><a href="https://launchpad.net/loggerhead">Loggerhead</a> is a webfrontend for <a href="http://bazaar.canonical.com/">Bazaar</a> (usually abbreviated as bzr) repositories. Bazaar is a so-called distributed version control system. So, if you have one or more bzr repositories you can use Loggerhead to look at the files, read the change logs and see the differences between revisions from within your web browser.</p>
<p>The main purpose of this post is to document the steps needed to configure Loggerhead and Apache to work together to publish your bzr repos on the web. The need for this post arose when I tried to get this setup to work and found that there isn&#8217;t a lot of documentation on how to get this done and most of it is out of date. The folowing steps were performed on a Linux server with Ubuntu 11.04 installed.</p>
<h2>Basic Loggerhead configuration</h2>
<p>First, let&#8217;s install Loggerhead:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> loggerhead</pre></div></div>

<p>Although the package is called loggerhead, the actual binary that is run is called serve-branches. The package provides start and stop scripts for the service (<code>/etc/init.d/loggerhead</code>), but to start successfully the file <code>/etc/serve-branches.conf</code> needs to exist. Older documentation I found on the web refers to the file <code>/etc/loggerhead.conf</code>, but that file has become obsolete.</p>
<p>The <code>serve-branches.conf</code> file contains three lines:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">served_branches</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/home/bzr</span>
<span style="color: #000099;">prefix</span><span style="color: #000066; font-weight:bold;">=</span>
<span style="color: #000099;">port</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">8080</span></pre></div></div>

<p>Here, the line <code>served_branches</code> points to the directory under which you store your bzr repositories. Each repo needs to be stored in its own directory. So in this example all the repos are in subdirectories of <code>/home/bzr/</code>.</p>
<p>You have to make sure that loggerhead can read the files in that directory. Loggerhead runs as the <code>loggerhead</code> user but I made the directories readable and accessible by all users:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> a+rx <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bzr<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>If you now start Loggerhead:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ service start loggerhead</pre></div></div>

<p>you should be able to visit http://localhost:8080 in your browser and see your repositories.</p>
<h2>How to publish your branch to this shared repository?</h2>
<p>Now that our repository browser is set up, how do we publish our branches to it so that there actually is something to browse through? Here is how you publish your branch to the server, assuming that you are in a directory that contains a branch and want to publish it as <code>myTests</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ bzr push <span style="color: #660033;">--create-prefix</span> sftp:<span style="color: #000000; font-weight: bold;">//</span>username<span style="color: #000000; font-weight: bold;">@</span>server.yourdomain.com<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bzr<span style="color: #000000; font-weight: bold;">/</span>myTests</pre></div></div>

<p>As you probably suspected, the <code>--create-prefix</code> option is only necessary the first time you push your branch. Note that we are using sftp here. Loggerhead itself doesn&#8217;t allow writes to the published repos. So, every user that want to push his/her changes to this repository needs to have sftp access to the <code>/home/bzr</code> directory. I solved that problem by adding all people that need to be able to push changes to a Linux group called <i>vcs</i> (for Version Control Systems) and then set the primary group of <code>/home/bzr/</code> to <i>vcs</i> as well as giving group write permissions to this directory:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #660033;">-ld</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bzr<span style="color: #000000; font-weight: bold;">/</span>
drwxrwxr-x <span style="color: #000000;">4</span> root vcs <span style="color: #000000;">4096</span> <span style="color: #000000;">2011</span>-08-<span style="color: #000000;">16</span> <span style="color: #000000;">23</span>:<span style="color: #000000;">10</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>bzr<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<h2>Adding Apache to the mix</h2>
<p>In my case I already have a web server (Apache) running on port 80. Since I&#8217;d rather not open yet another port (8080 in this case) on my router, I wanted to use Apache to hand over the requests for bzr page to Loggerhead. For that I needed to install the following packages:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> python-pastedeploy</pre></div></div>

<p>Next, I needed to change the contents of the <code>/etc/serve-branches.conf</code> file to this:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000099;">served_branches</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/home/bzr</span>
<span style="color: #000099;">prefix</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/bzr</span>
<span style="color: #000099;">port</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">8080</span></pre></div></div>

<p>The prefix indicates the location in the URL where Apache will serve the repos. In this case that will be http://server.yourdomain.com/bzr/.</p>
<p>And finally I needed to configure Apache. First, make sure that the <code>proxy</code> and <code>proxy-http</code> modules are loaded:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ a2enmod proxy proxy_http</pre></div></div>

<p>Next, create a file <code>/etc/apache/conf.d/sites-available/loggerhead</code> with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># Configuration for browsing of Bazaar repos. Make sure loggerhead is running.</span>
&lt;<span style="color: #000000; font-weight:bold;">Location</span> <span style="color: #7f007f;">&quot;/bzr/&quot;</span>&gt;
    <span style="color: #00007f;">ProxyPass</span> http://127.0.0.1:<span style="color: #ff0000;">8080</span>/
    <span style="color: #00007f;">ProxyPassReverse</span> http://127.0.0.1:<span style="color: #ff0000;">8080</span>/
&lt;/<span style="color: #000000; font-weight:bold;">Location</span>&gt;</pre></div></div>

<p>Note that Loggerhead and Apache run on the same host, that&#8217;s why I set the IP to 127.0.0.1.</p>
<p>Finally it&#8217;s time to enable the site and restart Apache:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ a2ensite loggerhead
$ service apache2 restart</pre></div></div>

<p>Now it should be possible to browse your repos at http://server.yourdomain.com/bzr/. Note the final <code>/</code>, it&#8217;s important.</p>
<h2>Securing access with an LDAP connection</h2>
<p>I have stored all my Unix user and group information in an LDAP server. To make sure that only people in the Unix group <code>vcs</code> are allowed access to the loggerhead pages, change the Apache configuration file <code>loggerhead</code> to the following:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #adadad; font-style: italic;"># Configuration for browsing of Bazaar repos. Make sure loggerhead is running.</span>
&lt;<span style="color: #000000; font-weight:bold;">Location</span> <span style="color: #7f007f;">&quot;/bzr/&quot;</span>&gt;
    <span style="color: #00007f;">ProxyPass</span> http://127.0.0.1:<span style="color: #ff0000;">8080</span>/
    <span style="color: #00007f;">ProxyPassReverse</span> http://127.0.0.1:<span style="color: #ff0000;">8080</span>/
&nbsp;
    <span style="color: #adadad; font-style: italic;"># LDAP authentication</span>
    <span style="color: #00007f;">AuthType</span> Basic
    <span style="color: #00007f;">AuthName</span> <span style="color: #7f007f;">&quot;Karssen.org VCS users&quot;</span>
    <span style="color: #00007f;">AuthBasicProvider</span> ldap
    <span style="color: #00007f;">AuthLDAPURL</span> <span style="color: #7f007f;">&quot;ldap://ldap.yourdomain.com/ou=Users,dc=yourdomain,dc=com?uid&quot;</span>
    <span style="color: #00007f;">AuthLDAPGroupAttribute</span> memberUid
    <span style="color: #00007f;">AuthLDAPGroupAttributeIsDN</span> <span style="color: #0000ff;">off</span>
    <span style="color: #00007f;">Order</span> <span style="color: #00007f;">Allow</span>,<span style="color: #00007f;">Deny</span>
    <span style="color: #00007f;">Allow</span> From <span style="color: #0000ff;">All</span>
    <span style="color: #00007f;">Require</span> ldap-<span style="color: #00007f;">group</span> cn=vcs,ou=Groups,dc=yourdomain,dc=com
&lt;/<span style="color: #000000; font-weight:bold;">Location</span>&gt;</pre></td></tr></table></div>

<p>Lines 11 and 12 are needed because the <code>vcs</code> group is not an LDAP group. I store my Unix (POSIX) groups in a separate OU in the LDAP tree (see line 15).<br />
Don&#8217;t forget to restart Apache after making these changes.</p>
<h2>References</h2>
<ul>
<li><a href="http://doc.bazaar.canonical.com/latest/en/admin-guide/code-browsing.html">Bazaar documentation on Apache integration</a></li>
<li><a href="https://bugs.launchpad.net/ubuntu/+source/loggerhead/+bug/563118">Launchpad bug 563118 describing the unexpected change from <code>loggerhead.conf</code> to <code>serve-branches.conf</code></a></li>
<li><a href="http://blather.michaelwlucas.com/archives/99">Apache, LDAP and groups</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/08/22/installing-loggerhead-behind-apache-on-ubuntu-11-04/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Embedding album art in FLAC files</title>
		<link>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/</link>
		<comments>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 18:44:53 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Bash]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=149</guid>
		<description><![CDATA[I recently wanted to add cover art to my collection of FLAC-encoded audio files. I wrote the following simple script to help me automate the process. Running this script in a given directory (I group my music in directories per artist, followed by a subdirectory for each album) with the name of the album art [...]]]></description>
			<content:encoded><![CDATA[<p>I recently wanted to add cover art to my collection of FLAC-encoded audio files. I wrote the following simple script to help me automate the process. Running this script in a given directory (I group my music in directories per artist, followed by a subdirectory for each album) with the name of the album art image file name as argument then automatically embeds the image in the FLAC/Vorbis tag.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script embeds a given image (usually .jpg) as album art in the</span>
<span style="color: #666666; font-style: italic;"># FLAC files in the present directory (and its subdirectories).</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Time-stamp: &lt;2011-07-31 20:43:23 (lennart)&gt;</span>
&nbsp;
<span style="color: #007800;">coverart</span>=<span style="color: #007800;">$1</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*.flac&quot;</span> <span style="color: #660033;">-print0</span> <span style="color: #000000; font-weight: bold;">|</span><span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #660033;">-0</span> metaflac <span style="color: #660033;">--import-picture-from</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$coverart</span>&quot;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/07/31/embedding-album-art-in-flac-files/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing and configuring Puppet</title>
		<link>http://blog.karssen.org/2011/07/29/installing-and-configuring-puppet/</link>
		<comments>http://blog.karssen.org/2011/07/29/installing-and-configuring-puppet/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 16:26:08 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[Puppet]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=135</guid>
		<description><![CDATA[Puppet is a configuration management system. In short this means that by setting up a server (the Puppet master) you can manage many other machines (nodes) with this server by specifying which packages should be installed, files that need to be present, their permissions, etc. The nodes poll the server every 30 minutes (by default) [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.puppetlabs.com/puppet/introduction/">Puppet</a> is a configuration management system. In short this means that by setting up a server (the Puppet master) you can manage many other machines (nodes) with this server by specifying which packages should be installed, files that need to be present, their permissions, etc. The nodes poll the server every 30 minutes (by default) to see if they should apply any changes to their configuration. Other packages that implement a similar idea are CfEnfine and Chef.</p>
<p>Note that all these instructions were performed as root.</p>
<h2>The puppet master</h2>
<p>Gaffel will be puppet master. I&#8217;ve added a DNS entry for <i>puppet.karssen.org</i> that points to <i>gaffel</i>. This installs the client and the Puppet master:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> puppet puppetmaster</pre></div></div>

<p>The main configuration of server and client can be found in <i>/etc/puppet/puppet.conf</i>. We&#8217;ll leave it at the default for now. The file <i>/etc/puppet/manifests/sites.pp</i> contains options that apply to the whole site. Let&#8217;s make it and add the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">import <span style="color: #933;">&quot;nodes&quot;</span>
&nbsp;
# The filebucket is for backups. Originals of files that Puppet modifies
# get stored here.
filebucket <span style="">&#123;</span> main: server <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; 'puppet.karssen.org' <span style="">&#125;</span></span>
File  <span style="">&#123;</span> backup <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; main<span style="">&#125;</span></span>
&nbsp;
# Set the default $PATH$ for executing commands on node systems.
Exec <span style="">&#123;</span> path <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/usr/bin:/usr/sbin:/bin:/sbin:&quot;</span> <span style="">&#125;</span></pre></div></div>

<p>The file <i>/etc/puppet/manifests/nodes.pp</i> defines the nodes/clients that will be managed by puppet as well as what configuration will be applied to them, so-called roles. For now, let&#8217;s make a quick example:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">node common <span style="">&#123;</span>
	include packages
<span style="">&#125;</span>
&nbsp;
node lambik inherits common <span style="">&#123;</span>
	include ntp::client
<span style="">&#125;</span></pre></div></div>

<p>Both the &#8216;packages&#8217; and the &#8216;ntp&#8217; modules still need to be defined. Let&#8217;s do that now.</p>
<p>Modules are collections of puppet code (known as manifests) and related files that are used for client configuration. Modules are stored in <i>/etc/puppet/modules/</i>.<br />
Let&#8217;s start with the ntp example. First make the necessary directory structure:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>ntp<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>manifests,files,templates<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Every modules needs a file <i>init.pp</i> that declares the class. It can also include other files. The <i>files</i> and <i>templates</i> directories are used to store files that need to be copied to the node or templates to make such files, respectively. We&#8217;ll come across some examples of both. This is the <i>init.pp</i> file for the ntp role (<i>/etc/puppet/modules/ntp/manifests/init.pp</i>):</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">class ntp::client <span style="">&#123;</span>
	 package <span style="">&#123;</span> <span style="color: #933;">&quot;ntp&quot;</span>:
    		 <span style="color: #000099;">ensure</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; installed,</span>
	 <span style="">&#125;</span>
&nbsp;
	 service <span style="">&#123;</span> <span style="color: #933;">&quot;ntp_client&quot;</span>:
		 <span style="color: #000099;">name</span>       <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;ntp&quot;</span>
    		 <span style="color: #000099;">ensure</span>     <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; running,</span>
#		 hasstatus  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
		 <span style="color: #000099;">hasrestart</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
		 <span style="color: #000099;">require</span>    <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Package<span style="">&#91;</span></span><span style="color: #933;">&quot;ntp&quot;</span><span style="">&#93;</span>,
	 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>Here we indicate that the NTP service must be running and that it&#8217;s init script (in <i>/etc/init.d</i>) accepts the <i>status</i> and <i>restart</i> options. Lastly in the <i>require</i> line we note that before this manifest can be applied we must make sure that the package <i>ntp</i> has been installed. This is necessary, because the order in which the two directives are executed is not necessarily the order in<br />
which they appear in the manifest.</p>
<p>The <i>#</i> in from of the <i>hasstatus</i> attribute is because of a bug inthe puppet version (2.6.4) shipped with Ubuntu 11.04. See http://projects.puppetlabs.com/issues/5610 for the bug report. In version 2.6.7 it is supposedly fixed.</p>
<p>In our <i>nodes.pp</i> file we also mentioned a <i>packages</i> class. In this class we list all the packages that we want to have installed on the node. Let&#8217;s make the <i>packages</i> module. First create the necessary directories:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>packages<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>manifests,files,templates<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Add the file <i>/etc/puppet/modules/packages/manifests/init.pp</i>:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">class packages <span style="">&#123;</span>
	 $base_packages <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> <span style="">&#91;</span></span>
	 <span style="color: #933;">&quot;openssh-server&quot;</span>,
	 <span style="color: #933;">&quot;nfs-common&quot;</span>,
	 <span style="color: #933;">&quot;etckeeper&quot;</span>,
	 <span style="color: #933;">&quot;htop&quot;</span>,
	 <span style="color: #933;">&quot;iotop&quot;</span>,
	 <span style="color: #933;">&quot;iftop&quot;</span>,
	 <span style="">&#93;</span>
&nbsp;
	 $editor_packages <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> <span style="">&#91;</span></span>
	 <span style="color: #933;">&quot;emacs&quot;</span>,
	 <span style="color: #933;">&quot;emacs-goodies-el&quot;</span>,
	 <span style="color: #933;">&quot;elscreen&quot;</span>,
	 <span style="">&#93;</span>
&nbsp;
	 $all_packages <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> <span style="">&#91;</span></span>
	 $base_packages,
	 $editor_packages,
	 <span style="">&#93;</span>
&nbsp;
	 package <span style="">&#123;</span> $all_packages:
	      <span style="color: #000099;">ensure</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; installed,</span>
	 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>Here I&#8217;ve defined three variables (beginning with a <i>$</i> sign), one for base packages, one for editor-related packages and one called <i>$all_packages</i> that incorporates them both. Finally, I tell puppet to ensure they are all installed.</p>
<h2>Setting up a client</h2>
<p>As a test client I&#8217;m using <i>lambik</i>, one of my MythTV frontends.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> puppet</pre></div></div>

<p>To make sure that puppet starts by default on system startup edit the file <i>/etc/default/puppet</i> and set <i>START</i> to <i>yes</i>:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># Defaults for puppet - sourced by /etc/init.d/puppet
&nbsp;
# Start puppet on boot?
<span style="color: #000099;">START</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">yes</span>
&nbsp;
# Startup options
<span style="color: #000099;">DAEMON_OPTS</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #933;">&quot;&quot;</span></pre></div></div>

<p>Now edit <i>/etc/puppet/puppet.conf</i> (on the client) and add the FQDN of the puppet master server to the <i>[main]</i> section:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"><span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>main<span style="">&#93;</span></span>
<span style="color: #000099;">logdir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/log/puppet</span>
<span style="color: #000099;">vardir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/lib/puppet</span>
<span style="color: #000099;">ssldir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/lib/puppet/ssl</span>
<span style="color: #000099;">rundir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/var/run/puppet</span>
<span style="color: #000099;">factpath</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">$vardir/lib/facter</span>
<span style="color: #000099;">templatedir</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">$confdir/templates</span>
<span style="color: #000099;">prerun_command</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/etc/puppet/etckeeper-commit-pre</span>
<span style="color: #000099;">postrun_command</span><span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">/etc/puppet/etckeeper-commit-post</span>
<span style="color: #000099;">server</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> puppet.karssen.org</span>
&nbsp;
<span style="color: #000066; font-weight:bold;"><span style="">&#91;</span>master<span style="">&#93;</span></span>
# These are needed when the puppetmaster is run by passenger
# and can safely be removed if webrick is used.
<span style="color: #000099;">ssl_client_header</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> SSL_CLIENT_S_DN</span>
<span style="color: #000099;">ssl_client_verify_header</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> SSL_CLIENT_VERIFY</span></pre></div></div>

<h2>Setting up secure communication between master and nodes and first test run</h2>
<p>Puppet uses SSL certificates to set up a secure connection between master and nodes. Before you can apply any changes to the client, certificates need to be exchanged and signed. First, tell the client to connect to the puppet master:</p>
<pre lang="">
$ puppetd --test
info: Creating a new SSL key for lambik.karssen.org
warning: peer certificate won't be verified in this SSL session
info: Caching certificate for ca
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
info: Creating a new SSL certificate request for lambik.karssen.org
info: Certificate Request fingerprint (md5): 1D:A3:3A:4A:A6:DA:D6:C8:96:F4:D4:7E:52:F4:12:1D
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
Exiting; no certificate found and waitforcert is disabled
</pre>
<p>On the puppet master we can now sign the certificate:</p>
<pre lang="">
$ puppetca -l
lambik.karssen.org
$ puppetca -s lambik.karssen.org
notice: Signed certificate request for lambik.karssen.org
notice: Removing file Puppet::SSL::CertificateRequest lambik.karssen.org at '/var/lib/puppet/ssl/ca/requests/lambik.karssen.org.pem'
</pre>
<p>On the client we can now rerun <i>puppetd</i>:</p>
<pre lang="">
root@lambik:~# puppetd --test
info: Caching catalog for lambik.karssen.org
info: Applying configuration version '1311930908'
notice: /Stage[main]/Packages/Package[iotop]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Packages/Package[iftop]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Ntp/Package[ntp]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Packages/Package[emacs-goodies-el]/ensure: ensure changed 'purged' to 'present'
notice: /Stage[main]/Packages/Package[htop]/ensure: ensure changed 'purged' to 'present'
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 78.43 seconds
</pre>
<p>If all went well, we can now start the puppet client daemon to keep our system under puppet control:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ service puppet start</pre></div></div>

<h2>Adding (configuration) files to the roles</h2>
<p>Since I run my own NTP server (<i>ntp.karssen.org</i>, only accessible from inside my LAN), the NTP configuration file (<i>/etc/ntp.conf</i>) must be changed. Of course, we want Puppet to take care of this. The <i>ntp.conf</i> file I want to distribute to all nodes has the following contents (note that the only change is the name of the server and commenting the <i>restrict</i> lines):</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;"># /etc/ntp.conf, configuration for ntpd<span style="color: #666666; font-style: italic;">; see ntp.conf(5) for help</span>
&nbsp;
driftfile /var/lib/ntp/ntp.drift
&nbsp;
&nbsp;
# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/
&nbsp;
statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable
&nbsp;
# Specify one or more NTP servers.
&nbsp;
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on <span style="">2011</span>-02-08 <span style="">&#40;</span>LP: #<span style="">104525</span><span style="">&#41;</span>. See http://www.pool.ntp.org/join.html for
# more information.
server ntp.karssen.org
&nbsp;
# Use Ubuntu's ntp server as a fallback.
server ntp.ubuntu.com
&nbsp;
# Access control configuration<span style="color: #666666; font-style: italic;">; see /usr/share/doc/ntp-doc/html/accopt.html for</span>
# details.  The web page &lt;http://support.ntp.org/bin/view/Support/AccessRestrict
ions&gt;
# might also be helpful.
#
# Note that <span style="color: #933;">&quot;restrict&quot;</span> applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.
&nbsp;
# By default, exchange time with everybody, but don't allow configuration.
#restrict -<span style="">4</span> default kod notrap nomodify nopeer noquery
#restrict -<span style="">6</span> default kod notrap nomodify nopeer noquery
&nbsp;
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::<span style="">1</span>
&nbsp;
# Clients from this <span style="">&#40;</span>example!<span style="">&#41;</span> subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust
&nbsp;
&nbsp;
# If you want to provide time to your local subnet, change the next line.
# <span style="">&#40;</span>Again, the address is an example only.<span style="">&#41;</span>
#broadcast 192.168.123.255
&nbsp;
# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient</pre></div></div>

<p>Save this file in <i>/etc/puppet/modules/ntp/files</i> (on the puppet master). Now edit the manifest for the ntp role (<i>/etc/puppet/modules/ntp/manifest/init.pp</i>) to add the file section and a <i>subscribe</i> command:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">class ntp::client <span style="">&#123;</span>
	 package <span style="">&#123;</span> <span style="color: #933;">&quot;ntp&quot;</span>:
		      <span style="color: #000099;">ensure</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; installed,</span>
	 <span style="">&#125;</span>
&nbsp;
	 service <span style="">&#123;</span> <span style="color: #933;">&quot;ntp_client&quot;</span>:
	      <span style="color: #000099;">name</span>       <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;ntp&quot;</span>,
	      <span style="color: #000099;">ensure</span>     <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; running,</span>
#	      hasstatus  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
	      <span style="color: #000099;">hasrestart</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
	      <span style="color: #000099;">require</span>    <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Package<span style="">&#91;</span></span><span style="color: #933;">&quot;ntp&quot;</span><span style="">&#93;</span>,
	      <span style="color: #000099;">subscribe</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; File<span style="">&#91;</span></span><span style="color: #933;">&quot;ntp_client_config&quot;</span><span style="">&#93;</span>,
	 <span style="">&#125;</span>
&nbsp;
	 file <span style="">&#123;</span> <span style="color: #933;">&quot;ntp_client_config&quot;</span>:
		   <span style="color: #000099;">path</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/etc/ntp.conf&quot;</span>,
	   <span style="color: #000099;">owner</span>   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; root,</span>
	   <span style="color: #000099;">group</span>   <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; root,</span>
	   <span style="color: #000099;">mode</span>    <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; 644,</span>
	   <span style="color: #000099;">source</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;puppet:///ntp/ntp.conf&quot;</span>,
	   <span style="color: #000099;">require</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Package<span style="">&#91;</span></span><span style="color: #933;">&quot;ntp&quot;</span><span style="">&#93;</span>,
	 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>The URL specified in the <i>source</i> line automatically looks in the right place (as mentioned just above) for the file. Because we don&#8217;t want to wait for puppet to automatically pass on this configuration, let&#8217;s run it by hand:</p>

<div class="wp_syntax"><div class="code"><pre class="diff" style="font-family:monospace;">root@lambik:~# puppetd --test
info: Caching catalog for lambik.karssen.org
info: Applying configuration version '<span style="">1311936811</span>'
<span style="color: #888822;">--- /etc/ntp.conf	2011-06-17 07:59:54.000000000 +0200</span>
<span style="color: #888822;">+++ /tmp/puppet-file20110729-12128-1h3fupz-0	2011-07-29 12:53:33.279622938 +0200</span>
<span style="color: #440088;">@@ -16,16 +16,14 @@</span>
 # Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
 # on <span style="">2011</span>-02-08 <span style="">&#40;</span>LP: #<span style="">104525</span><span style="">&#41;</span>. See http://www.pool.ntp.org/join.html for
 # more information.
<span style="color: #991111;">-server 0.ubuntu.pool.ntp.org</span>
<span style="color: #991111;">-server 1.ubuntu.pool.ntp.org</span>
<span style="color: #991111;">-server 2.ubuntu.pool.ntp.org</span>
<span style="color: #991111;">-server 3.ubuntu.pool.ntp.org</span>
<span style="color: #00b000;">+server ntp.karssen.org</span>
&nbsp;
 # Use Ubuntu's ntp server as a fallback.
 server ntp.ubuntu.com
&nbsp;
<span style="color: #440088;">@@ -33,8 +31,8 @@</span>
 # up blocking replies from your own upstream servers.
&nbsp;
 # By default, exchange time with everybody, but don't allow configuration.
<span style="color: #991111;">-restrict -4 default kod notrap nomodify nopeer noquery</span>
<span style="color: #991111;">-restrict -6 default kod notrap nomodify nopeer noquery</span>
<span style="color: #00b000;">+#restrict -4 default kod notrap nomodify nopeer noquery</span>
<span style="color: #00b000;">+#restrict -6 default kod notrap nomodify nopeer noquery</span>
&nbsp;
 # Local users may interrogate the ntp server more closely.
 restrict 127.0.0.1
info: FileBucket adding /etc/ntp.conf as <span style="">&#123;</span>md5<span style="">&#125;</span><span style="color: #440088;">32280703a4</span>ba7aa<span style="color: #440088;">1148c48895097</span>ed07
info: /Stage<span style="">&#91;</span>main<span style="">&#93;</span>/Ntp::Client/File<span style="">&#91;</span>ntp_client_config<span style="">&#93;</span>: Filebucketed /etc/ntp.conf to main with sum <span style="color: #440088;">32280703a4</span>ba7aa<span style="color: #440088;">1148c48895097</span>ed07
notice: /Stage<span style="">&#91;</span>main<span style="">&#93;</span>/Ntp::Client/File<span style="">&#91;</span>ntp_client_config<span style="">&#93;</span>/content: content changed '<span style="">&#123;</span>md5<span style="">&#125;</span><span style="color: #440088;">32280703a4</span>ba7aa<span style="color: #440088;">1148c48895097</span>ed07' to '<span style="">&#123;</span>md5<span style="">&#125;</span><span style="color: #440088;">0d1</span>b<span style="color: #440088;">81c95</span>bab1f6b08eb27dfaeb18bb5'
info: /Stage<span style="">&#91;</span>main<span style="">&#93;</span>/Ntp::Client/File<span style="">&#91;</span>ntp_client_config<span style="">&#93;</span>: Scheduling refresh of Service<span style="">&#91;</span>ntp_client<span style="">&#93;</span>
notice: /Stage<span style="">&#91;</span>main<span style="">&#93;</span>/Ntp::Client/Service<span style="">&#91;</span>ntp_client<span style="">&#93;</span>: Triggered 'refresh' from <span style="">1</span> events
notice: Finished catalog run in <span style="">3.06</span> seconds</pre></div></div>

<h2>Setting NFS mounts in <i>/etc/fstab</i></h2>
<p>On my clients I want to mount several NFS shares. Let&#8217;s create the directories for the <i>nfs_mounts</i> module (on the puppet master of course):</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>puppet<span style="color: #000000; font-weight: bold;">/</span>modules<span style="color: #000000; font-weight: bold;">/</span>nfs_mounts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>manifests,files,templates<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></div></div>

<p>Next, let&#8217;s edit the manifest (<i>/etc/puppet/modules/nfs_mounts/manifests/init.pp</i>):</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">class nfs_mounts <span style="">&#123;</span>
	 # Create the shared folder unless it already exists
	 exec <span style="">&#123;</span> <span style="color: #933;">&quot;/bin/mkdir -p /var/sharedtmp/&quot;</span>:
		   <span style="color: #000099;">unless</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/usr/bin/test -d /var/sharedtmp/&quot;</span>,
	 <span style="">&#125;</span>
&nbsp;
	 mount <span style="">&#123;</span> <span style="color: #933;">&quot;/var/sharedtmp/&quot;</span>:
	    <span style="color: #000099;">atboot</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
	    <span style="color: #000099;">ensure</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; mounted,</span>
	    <span style="color: #000099;">device</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;nfs.karssen.org:/var/sharedtmp&quot;</span>,
	    <span style="color: #000099;">fstype</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;nfs&quot;</span>,
	    <span style="color: #000099;">options</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;vers=3&quot;</span>,
	    <span style="color: #000099;">require</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; Package<span style="">&#91;</span></span><span style="color: #933;">&quot;nfs-common&quot;</span><span style="">&#93;</span>,
	 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>This should make the <i>/var/sharedtmp</i> directory and mount it. Note that I mention the <i>nfs_common</i> package in a <i>require</i> line. This package was defined in the <i>packages</i> module (in the <i>$base_packages</i> variable. Now let&#8217;s add this module to the <i>nodes.pp</i> file:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">node common <span style="">&#123;</span>
  include packages
<span style="">&#125;</span>
&nbsp;
node lambik inherits common <span style="">&#123;</span>
	include ntp::client
	include nfs_mounts
<span style="">&#125;</span></pre></div></div>

<p>Since I&#8217;ve got more than a single NFS mount, let&#8217;s extend the previous example and use a defined resource. Change the file <i>/etc/puppet/modules/nfs_mounts/manifests/init.pp</i> as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">define nfs_mount<span style="">&#40;</span>
	  $location,
	  $server  <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;nfs.karssen.org&quot;</span>,
	  $options <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;vers=3&quot;</span>,
	  $fstype  <span style="color: #000066; font-weight:bold;">=</span> <span style="color: #933;">&quot;nfs&quot;</span>
<span style="">&#41;</span> <span style="">&#123;</span>
  file <span style="">&#123;</span><span style="color: #933;">&quot;$location&quot;</span>:
	  <span style="color: #000099;">ensure</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; directory,</span>
  <span style="">&#125;</span>
&nbsp;
  mount <span style="">&#123;</span> <span style="color: #933;">&quot;$location&quot;</span>:
  	<span style="color: #000099;">atboot</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; true,</span>
	<span style="color: #000099;">ensure</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; mounted,</span>
	<span style="color: #000099;">device</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;${server}:${location}&quot;</span>,
	<span style="color: #000099;">fstype</span>  <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;$fstype&quot;</span>,
	<span style="color: #000099;">options</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;$options&quot;</span>,
	<span style="color: #000099;">require</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; <span style="">&#91;</span> Package<span style="">&#91;</span></span><span style="color: #933;">&quot;nfs-common&quot;</span><span style="">&#93;</span>, File<span style="">&#91;</span><span style="color: #933;">&quot;$location&quot;</span><span style="">&#93;</span> <span style="">&#93;</span>,
  <span style="">&#125;</span>
<span style="">&#125;</span>
&nbsp;
class nfs_mounts <span style="">&#123;</span>
&nbsp;
			 nfs_mount <span style="">&#123;</span> <span style="color: #933;">&quot;/home&quot;</span>:
		 	   <span style="color: #000099;">location</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/home&quot;</span>,
		 <span style="">&#125;</span>
&nbsp;
			 nfs_mount <span style="">&#123;</span> <span style="color: #933;">&quot;/var/sharedtmp&quot;</span>:
		 	    <span style="color: #000099;">location</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/var/sharedtmp&quot;</span>,
 		 <span style="">&#125;</span>
&nbsp;
			 nfs_mount <span style="">&#123;</span> <span style="color: #933;">&quot;/var/video&quot;</span>:
	 	    	    <span style="color: #000099;">location</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/var/video&quot;</span>,
 		 <span style="">&#125;</span>
&nbsp;
			 nfs_mount <span style="">&#123;</span> <span style="color: #933;">&quot;/var/music&quot;</span>:
	 	    	    <span style="color: #000099;">location</span> <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;">&gt; </span><span style="color: #933;">&quot;/var/music&quot;</span>,
 		 <span style="">&#125;</span>
<span style="">&#125;</span></pre></div></div>

<p>Here we first define a resource called <i>nfs_mount</i>, which can accept various parameters, all of which have a default value, except <i>$location</i>. Secondly we ensure that this location is a directory and then we define how it should be mounted. In the subsequent class definition we use this <i>nfs_mount</i> resource several times to mount the various NFS shares.<br />
Note that it would have been easier if the definition of <i>nfs_mount</i> would have started with</p>

<div class="wp_syntax"><div class="code"><pre class="ini" style="font-family:monospace;">define nfs_mount <span style="">&#40;</span>
	  $location <span style="color: #000066; font-weight:bold;">=</span><span style="color: #660066;"> $name,</span></pre></div></div>

<p>because then the invocations of <i>nfs_mount</i> in the class would not<br />
need the <i>location =></i> line. Unfortunately this doesn&#8217;t work. It&#8217;s<br />
a known bug that has been fixed in version 2.6.5<br />
(http://projects.puppetlabs.com/issues/5061).</p>
<h2>Links</h2>
<ul>
<li>Article by Jes Fraser in the July 2011 edition of Linux Journal. A lot of this info was taken from this article.</li>
<li><a href="http://blog.fandotech.com/archives/938">A blog</a></li>
<li><a href="http://docs.puppetlabs.com/">The Puppet documentation</a></li>
<li><a href="http://docs.puppetlabs.com/guides/language_guide.html">The Puppet language guide</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/07/29/installing-and-configuring-puppet/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making a .deb package for software that doesn&#8217;t accept the DESTDIR variable in its Makefile</title>
		<link>http://blog.karssen.org/2011/04/06/making-a-deb-package-for-software-that-doesnt-accept-the-destdir-variable-in-its-makefile/</link>
		<comments>http://blog.karssen.org/2011/04/06/making-a-deb-package-for-software-that-doesnt-accept-the-destdir-variable-in-its-makefile/#comments</comments>
		<pubDate>Tue, 05 Apr 2011 22:07:13 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Debian]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=116</guid>
		<description><![CDATA[Because I&#8217;ll be deploying a new server in the near future and I want to keep it as clean as possible I decided (again) to try to find out how to create a .deb package (as used for example by Debian and Ubuntu Linux) for some software that doesn&#8217;t follow the autotools way of doing [...]]]></description>
			<content:encoded><![CDATA[<p>Because I&#8217;ll be deploying a new server in the near future and I want to keep it as clean as possible I decided (again) to try to find out how to create a .deb package (as used for example by <a href="http://www.debian.org">Debian</a> and <a href-"http://www.ubuntu.com">Ubuntu</a> Linux) for some software that doesn&#8217;t follow the autotools way of doing things. This time I found a/the way. But first some background info.</p>
<p>In the Unix/Linux world many programs are compiled from source in three steps:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>Usually the necessary files for this have been created using the <a href="http://www.gnu.org/software/hello/manual/automake/Autotools-Introduction.html#Autotools-Introduction">autotools</a>. The goal of the first step is to create a so-called <code>Makefile</code> that contains instructions on how to compile and install the files (as done in the two subsequent <code>make</code> steps.</p>
<p>Some software packages, however, include a ready-made <code>Makefile</code> that, in addition, doesn&#8217;t accept the environment variable <code>DESTDIR</code>. This last point is what makes packaging the application into a .deb file a bit tricky. The reason for this is that the package build scripts want to install the files of your application in a temporary directory and not into system-wide directories like <code>/usr/bin/</code> etc. during the packing process. As such, packaging does not require root privileges.</p>
<p>At work we use many programs and tool sets developed by ourselves and other scientists. I know from my own experience that setting up autotools for your program is not trivial. Actually, for lack of time I&#8217;ve never successfully done it and for most of the rather simple programs that I&#8217;ve written setting up a complete autoconf/automake environment seems a bit overkill. I usually ended up writing a simple <code>Makefile</code> that compiles to code and installs it (usually in <code>/usr/local/bin</code>).</p>
<p><a href="http://www.sph.umich.edu/csg/abecasis/merlin/index.html">Merlin</a> by Abecasis <i>et al</i>. is a great piece of software developed at the University of Michigan. However, as you may have expected by now, its <code>Makefile</code> does not accept the <code>DESTDIR</code> variable, instead running <code>make</code> tells you that in order to install in a different directory you&#8217;ll have to run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #007800;">INSTALLDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>some<span style="color: #000000; font-weight: bold;">/</span>other<span style="color: #000000; font-weight: bold;">/</span>directory</pre></div></div>

<p>Therefore, all quick and dirty .deb recipes one finds on the Internet do not work without some adaptations. So here is what I did to make a .deb of it. It won&#8217;t be a full tutorial on how to do packaging, see the references at the end of this post for that. I&#8217;ll assume here that you have your build environment set up (e.g. the <code>build-essential</code> and <code>fakeroot</code> packages, as well as some others).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-xzf</span> merlin-1.1.2.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> merlin-1.1.2
dh_make <span style="color: #660033;">--single</span> <span style="color: #660033;">--email</span> youremail<span style="color: #000000; font-weight: bold;">@</span>address <span style="color: #660033;">--file</span> ..<span style="color: #000000; font-weight: bold;">/</span>merlin-1.1.2.tar.gz</pre></div></div>

<p>Now the basic files are ready. Apart from the untarred source files the files needed for Debian packaging have also been created (in <code>merlin-1.1.2/debian</code>).</p>
<p>Time to make the necessary changes. First, since the Makefile included with merlin does not accept the <code>DESTDIR</code> variable that the Debian packaging system uses we&#8217;ll patch the Makefile in such a way that it works (I tried to fix this in the <code>debian/control</code> file, but in the end adapting the <code>Makefile</code> was much easier). I do this by changing the line</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">INSTALLDIR<span style="color: #004400;">=/</span>usr<span style="color: #004400;">/</span>local<span style="color: #004400;">/</span>bin</pre></div></div>

<p>to</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;"><span style="color: #339900; font-style: italic;"># default installation directory</span>
<span style="color: #666622; font-weight: bold;">ifeq</span> <span style="color: #004400;">&#40;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">DESTDIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,</span><span style="color: #CC2200;">&quot;&quot;</span><span style="color: #004400;">&#41;</span>
    INSTALLDIR<span style="color: #004400;">=/</span>usr<span style="color: #004400;">/</span>local<span style="color: #004400;">/</span>bin<span style="color: #004400;">/</span>
<span style="color: #666622; font-weight: bold;">else</span>
    INSTALLDIR<span style="color: #004400;">=$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">DESTDIR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/</span>usr<span style="color: #004400;">/</span>bin<span style="color: #004400;">/</span>
<span style="color: #666622; font-weight: bold;">endif</span></pre></div></div>

<p>Let&#8217;s do some polishing of the package. I don&#8217;t want to make the perfect package, but adding a bit of text to the <code>debian/control</code> file make a lot of difference. This is what it looked like after my edits:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Source: merlin
Section: science
Priority: extra
Maintainer: Lennart C. Karssen &lt;youremail@address&gt;
Build-Depends: debhelper (&gt;= 7)
Standards-Version: 3.8.3
Homepage: http://www.sph.umich.edu/csg/abecasis/merlin/index.html
&nbsp;
Package: merlin
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Package for fast pedigree analysis
 MERLIN uses sparse trees to represent gene flow in pedigrees
 and is one of the fastest pedigree analysis packages around
 (Abecasis et al, 2002).</pre></div></div>

<p>Also editing the file <code>debian/changelog</code> is a good idea, especially since I changed the source code (remember the <code>Makefile</code>?). This is what I wrote:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">merlin (1.1.2-1) unstable; urgency=low
&nbsp;
  * Initial release
  * Adjusted Makefile to make DESTDIR work.
&nbsp;
 -- Lennart C. Karssen &lt;youremail@address&gt;  Tue, 05 Apr 2011 12:04:21 +0200</pre></div></div>

<p>Officially you should edit the <code>debian/copyright</code> file as well, but since the merlin licence doesn&#8217;t allow distribution of the source or the binaries I didn&#8217;t bother.</p>
<p>To finally build the package run</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">dpkg-buildpackage <span style="color: #660033;">-rfakeroot</span> <span style="color: #660033;">-us</span> <span style="color: #660033;">-uc</span></pre></div></div>

<p>This creates a <code>.deb</code> file in the directory where you started. As a final touch you can check your package for errors with</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">lintian ..<span style="color: #000000; font-weight: bold;">/</span>merlin_1.1.2-<span style="color: #000000;">1</span>_amd64.deb</pre></div></div>

<p>References:</p>
<ul>
<li>
<a href="http://www.debian.org/doc/maint-guide">http://www.debian.org/doc/maint-guide</a>
</li>
<li>
<a href="http://www.debian-administration.org/articles/337">http://www.debian-administration.org/articles/337</a>
</li>
<li>
<a href="http://www.webupd8.org/2010/01/how-to-create-deb-package-ubuntu-debian.html">http://www.webupd8.org/2010/01/how-to-create-deb-package-ubuntu-debian.html</a>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/04/06/making-a-deb-package-for-software-that-doesnt-accept-the-destdir-variable-in-its-makefile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using rsync to backup to a remote Synology Diskstation</title>
		<link>http://blog.karssen.org/2011/02/06/using-rsync-to-backup-to-a-remote-synology-diskstation/</link>
		<comments>http://blog.karssen.org/2011/02/06/using-rsync-to-backup-to-a-remote-synology-diskstation/#comments</comments>
		<pubDate>Sun, 06 Feb 2011 20:54:36 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[network]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=108</guid>
		<description><![CDATA[I recently bought a NAS, a Synology DiskStation DS211j and stuffed two 1TB disks in it. I configured the disks to be in RAID 1 (mirrored) in case one of them decides to die. I then brought the NAS to a family member&#8217;s house and installed it there. Now she uses it to back up [...]]]></description>
			<content:encoded><![CDATA[<p>I recently bought a NAS, a <a href="http://www.synology.com/nld/products/DS211j/index.php"> Synology DiskStation DS211j</a> and stuffed two 1TB disks in it. I configured the disks to be in RAID 1 (mirrored) in case one of them decides to die. I then brought the NAS to a family member&#8217;s house and installed it there. Now she uses it to back up her important files (and as a storage tank for music and videos).</p>
<p>The good thing for me is that I can now make off-site backups of my home directories. I configured the DS211j to accept SSH connections so that I can log into it (as user admin or root). I used the web interface to create a directory for my backups (which appeared to be <code>/volume1/BackupLennart</code> after logging in with SSH).</p>
<p>After making a hole in her firewall that allowed me to connect to the DS211j, I created a backup script in <code>/etc/cron.daily</code> with the following contents:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># This script makes a backup of my home dirs to a Synology DiskStation at</span>
<span style="color: #666666; font-style: italic;"># another location. I use LVM for my /home, so I make a snapshot first and</span>
<span style="color: #666666; font-style: italic;"># backup from there.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Time-stamp: &lt;2011-02-06 21:30:14 (lennart)&gt;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">###############################</span>
<span style="color: #666666; font-style: italic;"># Some settings</span>
<span style="color: #666666; font-style: italic;">###############################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># LVM options</span>
<span style="color: #007800;">VG</span>=raidvg01
<span style="color: #007800;">LV</span>=home
<span style="color: #007800;">MNTDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>mnt<span style="color: #000000; font-weight: bold;">/</span>home_rsync_snapshot<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># rsync options</span>
<span style="color: #007800;">DEST</span>=root<span style="color: #000000; font-weight: bold;">@</span>remote-machine.example.com:<span style="color: #000000; font-weight: bold;">/</span>volume1<span style="color: #000000; font-weight: bold;">/</span>BackupLennart<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #007800;">SRC</span>=<span style="color: #800000;">${MNTDIR}</span><span style="color: #000000; font-weight: bold;">/*</span>
<span style="color: #007800;">OPTIONS</span>=<span style="color: #ff0000;">&quot;-e ssh --delete --progress -azvhHS --numeric-ids --delete-excluded &quot;</span>
<span style="color: #007800;">EXCLUSIONS</span>=<span style="color: #ff0000;">&quot;--exclude lost+found --exclude .thumbnails --exclude .gvfs --exclude .cache --exclude Cache&quot;</span>
&nbsp;
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">###############################</span>
<span style="color: #666666; font-style: italic;"># The real work</span>
<span style="color: #666666; font-style: italic;">###############################</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Create the LVM snapshot</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$MNTDIR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #666666; font-style: italic;"># If the snapshot directory exists, another backup process may be</span>
    <span style="color: #666666; font-style: italic;"># running</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MNTDIR</span> already exists! Another backup still running?&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #660033;">-1</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #666666; font-style: italic;"># Let's make snapshots</span>
    <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$MNTDIR</span>
    lvcreate <span style="color: #660033;">-L5G</span> <span style="color: #660033;">-s</span> <span style="color: #660033;">-n</span> snap<span style="color: #007800;">$LV</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$VG</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$LV</span>
    <span style="color: #c20cb9; font-weight: bold;">mount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$VG</span><span style="color: #000000; font-weight: bold;">/</span>snap<span style="color: #007800;">$LV</span> <span style="color: #007800;">$MNTDIR</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;"># Do the actual backup</span>
rsync <span style="color: #007800;">$OPTIONS</span> <span style="color: #007800;">$EXCLUSIONS</span> <span style="color: #007800;">$SRC</span> <span style="color: #007800;">$DEST</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Remove the LVM snapshot</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$MNTDIR</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #c20cb9; font-weight: bold;">umount</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$VG</span><span style="color: #000000; font-weight: bold;">/</span>snap<span style="color: #007800;">$LV</span>
    lvremove <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$VG</span><span style="color: #000000; font-weight: bold;">/</span>snap<span style="color: #007800;">$LV</span>
    <span style="color: #c20cb9; font-weight: bold;">rmdir</span> <span style="color: #007800;">$MNTDIR</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$MNTDIR</span> does not exist!&quot;</span>
    <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #660033;">-1</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>

<p>Let&#8217;s walk through it: in the first section I configure several variables. Since I use LVM on my server, I can use it to make a snapshot of my /home partition. The LVM volume group I use is called &#8216;raidvg01&#8242;. Withing that VG my /home partition resides in a logical volume called &#8216;home&#8217;. The variable <code>MNTDIR</code> is the place where I mount the LVM snapshot of &#8216;home&#8217;.</p>
<p>The rsync options are quite straight forward. Check the rsync man page to find out what they mean. Note that I used the <code>--numeric-ids</code> option because the DS211j doesn&#8217;t have the same users as my server and this way all ownerships will still be correct if I ever need to restore from this backup.</p>
<p>In the section called &#8220;The real work&#8221; I first create the <code>MNTDIR</code> directory. Subsequently I create the LVM snapshot and mount it. After this the rsync backup can be run and finally I unmount the snapshot and remove it, followed by the removal of the <code>MNTDIR</code>.</p>
<p>Since the script is placed in <code>/etc/cron.daily</code> it will be executed every day. Since we use SSH to connect to the remote DS211j I set up SSH key access without a password. <a href="http://www.debian-administration.org/article/SSH_with_authentication_key_instead_of_password">This Debian howto</a> will tell you how to set that up.</p>
<p>The only thing missing in this setup is that the backups are not stored in an encrypted form on the remote NAS, but for now this is good enough. I can&#8217;t wait until the network bandwidth on both sides of this backup connection get so fast (and affordable) that I can easily sync my music as well. Right now uploads are so slow that I hardly dare to include those. I know that I shouldn&#8217;t complain since the Netherlands has one of the highest broadband penetrations in the world, but, hey, don&#8217;t you just always want a little more, just like Oliver Twist?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2011/02/06/using-rsync-to-backup-to-a-remote-synology-diskstation/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Recompiling the quota package in CentOS so that it can use LDAP to find email adresses</title>
		<link>http://blog.karssen.org/2010/10/19/recompiling-the-quota-package-in-centos-so-that-it-can-use-ldap-to-find-email-adresses/</link>
		<comments>http://blog.karssen.org/2010/10/19/recompiling-the-quota-package-in-centos-so-that-it-can-use-ldap-to-find-email-adresses/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 22:42:50 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[CentOS/RHEL]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=96</guid>
		<description><![CDATA[Today I compiled my first RPM package from source ! But let&#8217;s start at the beginning&#8230; At work I recently implemented disk quota on our server. While trying to setup /etc/warnquota.conf I noticed the example lines at the bottom that showed how to configure warnquota to look up e-mail addresses in an LDAP directory. This [...]]]></description>
			<content:encoded><![CDATA[<p>Today I compiled my first RPM package from source <img src='http://blog.karssen.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ! But let&#8217;s start at the beginning&#8230;</p>
<p>At work I recently implemented disk quota on our server. While trying to setup <code>/etc/warnquota.conf</code> I noticed the example lines at the bottom that showed how to configure warnquota to look up e-mail addresses in an LDAP directory. This was exactly what I needed, because we store our user&#8217;s e-mail address in our LDAP tree. Without this feature warnquota would try to send its warning mails to <code>user@our-server.example.com</code> instead of <user@example.com> (or even other addresses for guests that only visit us for a few weeks). The lines in <code>/etc/warnquota.conf</code> were:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">LDAP_MAIL = true
LDAP_HOST = ldap.example.com
LDAP_PORT = 389
LDAP_BASEDN = ou=Users,dc=example,dc=com
LDAP_SEARCH_ATTRIBUTE = uid
LDAP_MAIL_ATTRIBUTE = mail
LDAP_DEFAULT_MAIL_DOMAIN = example.com</pre></div></div>

<p>So, after saving the file I tested it by running  <code>warnquota -s</code> (as root, and I also made sure I reduced my own quota so I would be the one getting an e-mail warning).</p>
<p>Unfortunately warnquota spitted out some errors:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">warnquota: Error in config file (line 65), ignoring
warnquota: Error in config file (line 66), ignoring
warnquota: Error in config file (line 67), ignoring
warnquota: Error in config file (line 68), ignoring
warnquota: Error in config file (line 69), ignoring
warnquota: Error in config file (line 70), ignoring
warnquota: Warning: Mailer exitted abnormally.</pre></div></div>

<p>These were the line numbers with the LDAP options above <img src='http://blog.karssen.org/wp-includes/images/smilies/icon_sad.gif' alt=':-(' class='wp-smiley' /> . Google pointed me to <a href="https://bugzilla.redhat.com/show_bug.cgi?id=133207">an old bug in Fedora</a> that was marked as resolved. I also found out that the quota tools should be compiled with LDAP support for this to work. To be sure that it was actually possible I configured warnquota on my home server that runs Ubuntu 10.04 and also uses LDAP. There, it all worked as expected.</p>
<p>So, my next step was clear: make my own RPM package for <code>quota</code>. The one installed by CentOS 5.4 is <code>quota-3.13-1.2.5.el5</code>. These are the steps I took:</p>
<ul>
<li>Enable the CentOS source repository by creating the file <code>etc/yum.repos.d/CentOS-Source.repo</code> with this contents:

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">[centos-src]
name=CentOS $releasever - $basearch - Source
baseurl=http://mirror.centos.org/centos/$releasever/os/SRPMS/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5</pre></div></div>

<p>The run <code>yum update</code> and check that the new repository is listed.</p>
<li>Install the <code>yum-utils</code> and <code>rpmdevtools</code> packages: <code>sudo yum install yum-utils rpmdevtools</code>.
<li>Set up a directory to do your build work in. I created the directory <code>~/tmp/pkgtest</code>.
<li>Run <code>rpmdev-setuptree</code> to create the required sub directories.
<li>Set the basic build configuration by creating the file <code>~/.rpmmacros</code> with the following contents:

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;"># Path to top of build area
%_topdir    /home/lennart/tmp/pkgtest</pre></div></div>

<li>Go into the SRPMS directory and download the source package: <code>yumdownloader --source quota</code>
<li>In the top level directory run <code>rpm -i SRPMS/quota-3.13-1.2.5.el5.src.rpm</code> to unpack the package.
<li>The <code>SPECS</code> directory now contains the <code>.spec file</code> that contains the build instructions. The <code>SOURCES</code> directory contains the source files and patches from Red Hat. In a temporary directory I untar-ed the quotatools source tar.gz file and ran <code>./configure --help</code> to find out which option I should add to the spec file in order to enable LDAP lookup. The option was: <code>--enable-ldapmail=yes</code>. The set of configure lines in the spec file now looked like this:

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">%</span>build
<span style="color: #000000; font-weight: bold;">%</span>configure \
	--with-ext2<span style="color: #007800;">direct</span>=no <span style="color: #660033;">--enable-rootsbin</span> <span style="color: #660033;">--enable-ldapmail</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span>
<span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p>In the spec file I also added a changelog entry:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">* Mon Oct 18 2010 Lennart Karssen &lt;lennart@karssen.org 1:3.13-1.2.6
- Added --enable-ldapmail=try to the ./configure line to enable LDAP
  for looking up mail addresses. (Resolves Red Hat Bugzilla 133207,
  it is marked as resolved there, but apparently was reintroduced.)</pre></div></div>

<p>And I also bumped the build version number at the top of the file (the <code>Release:</code> line). Finally, I added <code>openldap-devel</code> to the <code>BuildPreReq</code> line (of course I ran into a compilation error first and then installed the <code>openldap-devel</code> package <img src='http://blog.karssen.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> ).</p>
<li>Now it&#8217;s time to build the package. In the <code>SPEC</code> directory run: <code>rpmbuild -bb quota.spec</code> and wait. The RPM package is created in the <code>RPMS</code> directory.
<li>Install the package: <code>sudo rpm -Uvh RPMS/x86_64/quota-3.13-1.2.6.x86_64.rpm</code> (if you didn&#8217;t bump the package version number the <code>--replacepkgs</code> must be added to &#8216;upgrade&#8217; to the same version).
</ul>
<p>And that was it! The package installed cleanly and a test run of <code>warnquota -s</code> was successful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2010/10/19/recompiling-the-quota-package-in-centos-so-that-it-can-use-ldap-to-find-email-adresses/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Nagios event handlers for services on remote machines</title>
		<link>http://blog.karssen.org/2010/09/14/nagios-event-handlers-for-services-on-remote-machines/</link>
		<comments>http://blog.karssen.org/2010/09/14/nagios-event-handlers-for-services-on-remote-machines/#comments</comments>
		<pubDate>Tue, 14 Sep 2010 13:44:28 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/?p=85</guid>
		<description><![CDATA[Part of my work consists of managing the servers on which we do our data analysis. At the moment we&#8217;ve got two servers and one virtual machine running. The VM is used as a management server, it runs things like Nagios, Cacti, Subversion, etc. Today I implemented Nagios event handlers in this setup. The idea [...]]]></description>
			<content:encoded><![CDATA[<p>Part of my work consists of managing the servers on which we do our data analysis. At the moment we&#8217;ve got two servers and one virtual machine running. The VM is used as a management server, it runs things like Nagios, Cacti, Subversion, etc. </p>
<p>Today I implemented Nagios event handlers in this setup. The idea behind an event handler is the following: If e.g. a service goes down, Nagios should try to solve this problem itself before notifying the administrator (me). It should, in this case, simply try to restart the service.</p>
<p>The Nagios documentation [<a href="#ref1">1</a>] describes how to do this for a service that runs on the same machine as the Nagios service. In my case, however, the services are running on the to real servers. To me it seemed logical to use NRPE to execute the necessary commands on the remote hosts (since NRPE was already running on those machines anyway).<br />
In order to adapt the scheme from the Nagios docs to work on remote servers as well three things need to be done:</p>
<ul>
<li>The command that is executed by the event handler script should be changed to use NRPE
<li>On the remote machine the <code>nagios</code> user (under which the NRPE service is running) should be given some sudo rights so that it is actually allowed to start a service.
<li>The NRPE configuration on the remote machine should of course be changed to include the new command(s) for starting services.
</ul>
<p>So here we go! First, the Nagios configuration on the management host. In the service definition file I added one line for the event handler to each service. The definition of one service now looks like this (the last line was added):</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">define service {
       use                      generic-service
       hostgroup_name           sge-exec-servers
       service_description      SGE execd
       check_command            check_nrpe_1arg!check_sge_execd
       notification_interval    0 ; set &gt; 0 if you want to be renotified
       event_handler            restart-service!sge-execd
}</pre></div></div>

<p>Next, the <code>restart-service</code> command must be defined. I did that in a file that I called <code>/etc/nagios3/conf.d/event-handlers.cfg</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">define command {
       command_name     restart-service
       command_line     /etc/nagios3/conf.d/event_handler_script.sh $SERVICESTATE$ $SERVICESTATETYPE $ $SERVICEATTEMPT$ $HOSTADDRESS$ $ARG1$ $SERVICEDESC$
}</pre></div></div>

<p>The variable <code>$ARG1$</code> here is the name of the service that needs to be restarted. In this example it is <code>sge-execd</code> from the <code>event_handler</code> line in the service definition. The <code>$HOSTADDRESS</code> will be used in the event handler script to send the right host name to NRPE.<br />
The <code>event_handler_script.sh</code> referenced here is almost identical to the one in the Nagios documentation. As mentioned in the plan above, I changed it slightly so that it uses NRPE.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh                                                                                            </span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Event handler script for restarting the nrpe server on the local machine</span>
<span style="color: #666666; font-style: italic;"># Taken from the Nagios documentation and</span>
<span style="color: #666666; font-style: italic;"># http://www.techadre.com/sites/techadre.com/files/event_handler_script_0.txt</span>
<span style="color: #666666; font-style: italic;"># Adapted by L.C. Karssen</span>
<span style="color: #666666; font-style: italic;"># Time-stamp: &lt;2010-09-14 15:24:33 (root)&gt;</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Note: This script will only restart the nrpe server if the service is</span>
<span style="color: #666666; font-style: italic;">#       retried 3 times (in a &quot;soft&quot; state) or if the web service somehow</span>
<span style="color: #666666; font-style: italic;">#       manages to fall into a &quot;hard&quot; error state.</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #007800;">date</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># What state is the NRPE service in?</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$1&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
OK<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #666666; font-style: italic;"># The service just came back up, so don't do anything...</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
WARNING<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #666666; font-style: italic;"># We don't really care about warning states, since the service is probably still running...</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
UNKNOWN<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #666666; font-style: italic;"># We don't know what might be causing an unknown error, so don't do anything...</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
CRITICAL<span style="color: #7a0874; font-weight: bold;">&#41;</span>
        <span style="color: #666666; font-style: italic;"># Aha!  The BLAH service appears to have a problem - perhaps we should restart the server...</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># Is this a &quot;soft&quot; or a &quot;hard&quot; state?</span>
        <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$2&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># We're in a &quot;soft&quot; state, meaning that Nagios is in the middle of retrying the</span>
        <span style="color: #666666; font-style: italic;"># check before it turns into a &quot;hard&quot; state and contacts get notified...</span>
        SOFT<span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #666666; font-style: italic;"># What check attempt are we on?  We don't want to restart the web server on the firs\</span>
t
                <span style="color: #666666; font-style: italic;"># check, because it may just be a fluke!</span>
                <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$3&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
&nbsp;
                <span style="color: #666666; font-style: italic;"># Wait until the check has been tried 3 times before restarting the web server.</span>
                <span style="color: #666666; font-style: italic;"># If the check fails on the 4th time (after we restart the web server), the state</span>
                <span style="color: #666666; font-style: italic;"># type will turn to &quot;hard&quot; and contacts will be notified of the problem.</span>
                <span style="color: #666666; font-style: italic;"># Hopefully this will restart the web server successfully, so the 4th check will</span>
                <span style="color: #666666; font-style: italic;"># result in a &quot;soft&quot; recovery.  If that happens no one gets notified because we</span>
                <span style="color: #666666; font-style: italic;"># fixed the problem!</span>
                <span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Restarting service $6 (3rd soft critical state)...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                        <span style="color: #666666; font-style: italic;"># Call NRPE to restart the service on the remote machine</span>
                        <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>plugins<span style="color: #000000; font-weight: bold;">/</span>check_nrpe <span style="color: #660033;">-H</span> <span style="color: #007800;">$4</span> <span style="color: #660033;">-c</span> restart-<span style="color: #007800;">$5</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$date</span> - restart $6 - SOFT&quot;</span>  <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>eventhandlers
                        <span style="color: #000000; font-weight: bold;">;;</span>
                        <span style="color: #000000; font-weight: bold;">esac</span>
                <span style="color: #000000; font-weight: bold;">;;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;"># The service somehow managed to turn into a hard error without getting fixed.</span>
        <span style="color: #666666; font-style: italic;"># It should have been restarted by the code above, but for some reason it didn't.</span>
        <span style="color: #666666; font-style: italic;"># Let's give it one last try, shall we?</span>
        <span style="color: #666666; font-style: italic;"># Note: Contacts have already been notified of a problem with the service at this</span>
        <span style="color: #666666; font-style: italic;"># point (unless you disabled notifications for this service)</span>
        HARD<span style="color: #7a0874; font-weight: bold;">&#41;</span>
                <span style="color: #000000; font-weight: bold;">case</span> <span style="color: #ff0000;">&quot;$3&quot;</span> <span style="color: #000000; font-weight: bold;">in</span>
&nbsp;
                <span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">&quot;Restarting $6 service...<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
                        <span style="color: #666666; font-style: italic;"># Call the init script to restart the NRPE server</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$date</span> - restart $6 - HARD&quot;</span>  <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>eventhandlers
                        <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>nagios<span style="color: #000000; font-weight: bold;">/</span>plugins<span style="color: #000000; font-weight: bold;">/</span>check_nrpe <span style="color: #660033;">-H</span> <span style="color: #007800;">$4</span> <span style="color: #660033;">-c</span> restart-<span style="color: #007800;">$5</span>
                        <span style="color: #000000; font-weight: bold;">;;</span>
                        <span style="color: #000000; font-weight: bold;">esac</span>
                <span style="color: #000000; font-weight: bold;">;;</span>
        <span style="color: #000000; font-weight: bold;">esac</span>
        <span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">0</span></pre></div></div>

<p>Now Nagios can be restarted and should continue its work as usual. Time to make the changes on the remote hosts.</p>
<p>First, we&#8217;ll grant the necessary sudo rights to the <code>nagios</code> user. Run <code>visudo</code> and add these lines:</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">## Allow NRPE to restart sevices
User_Alias NAGIOS = nagios,nagcmd
Cmnd_Alias NAGIOSCOMMANDS = /usr/sbin/service
Defaults:NAGIOS !requiretty
NAGIOS    ALL=(ALL)    NOPASSWD: NAGIOSCOMMANDS</pre></div></div>

<p>And finally add the required lines in the NRPE config file (<code>/etc/nagios/nrep.cfg</code>):</p>

<div class="wp_syntax"><div class="code"><pre class="conf" style="font-family:monospace;">command[restart-sge-execd]=/usr/bin/sudo /usr/sbin/service gridengine-exec start</pre></div></div>

<p>Restart the NRPE daemon and it should all work. Test it by manually stopping the service.</p>
<p>[<a name="ref1">1</a>] <a href="http://nagios.sourceforge.net/docs/3_0/eventhandlers.html">Nagios documentation on Event Handlers</a><br />
[2] <a href="http://www.techadre.com/content/nagios-event-handler-restarting-service">Two</a> blog <a href="http://www.techadre.com/content/nagios-event-handler-restart-remote-service">posts</a> that describe a similar set up. I used these as a starting point for my own set up. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2010/09/14/nagios-event-handlers-for-services-on-remote-machines/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lenovo Thinkpad X100e and Ubuntu 10.04</title>
		<link>http://blog.karssen.org/2010/09/12/lenovo-thinkpad-x100e-and-ubuntu-10-04/</link>
		<comments>http://blog.karssen.org/2010/09/12/lenovo-thinkpad-x100e-and-ubuntu-10-04/#comments</comments>
		<pubDate>Sun, 12 Sep 2010 14:58:52 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/2010/09/12/lenovo-thinkpad-x100e-and-ubuntu-10-04/</guid>
		<description><![CDATA[About a month ago I bought a Lenovo Thinkpad X100e laptop. Well, maybe laptop is a bit too big a word for it. Size-wise it&#8217;s more like a netbook with its screen diagonal of 11.6&#8243;. Performance-wise however, it&#8217;s much better. The one I&#8217;ve got has an AMD Turion Neo X2 L625 dual core processor running [...]]]></description>
			<content:encoded><![CDATA[<p>About a month ago I bought a Lenovo Thinkpad X100e laptop. Well, maybe laptop is a bit too big a word for it. Size-wise it&#8217;s more like a netbook with its screen diagonal of 11.6&#8243;. Performance-wise however, it&#8217;s much better. The one I&#8217;ve got has an AMD Turion Neo X2 L625 dual core processor running at a maximum of 1.6GHz and 2GB of RAM. It&#8217;s a nifty little machine that serves my needs: doing some work on the train to and from work, or while being on conferences. </p>
<p>I took quite some time to look around for a laptop like this, and this Thinkpad seems to be the only one that satisfies my minimum requirements:<br />
- Matte screen; no glossy screens for me, I&#8217;ve already got a mirror in my bathroom <img src='http://blog.karssen.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .<br />
- Trackpoint; yep, that&#8217;s the red dot in between the G, H, and B keys.<br />
- A processor that was more powerful than Intel&#8217;s Atom<br />
- A decent keyboard, because for me, using Linux means using the command line and Emacs a lot. </p>
<p>After several weeks of use I&#8217;ve found only one drawback to this machine: it&#8217;s processor is not that efficient. It uses quite some power and therefore gets a bit hot. As a result the fan runs a lot (even though it&#8217;s not that audible) and battery life is not too good. I&#8217;m getting approximately 2 to 3 hours out of it if I reduce the screen brightness and turn wifi off. That could have been better (maybe Lenovo should have used an Intel CULV processor?), but it&#8217;s not too much of a limitation. But this came at no surprise, most reviews on the web mention it.</p>
<p>After opening the box I quickly made an image of the Windows partitions that were on it and then proceeded to install Ubuntu 10.04 on it. Most of the hardware was recognised by the 2.6.32 kernel included with Ubuntu&#8217;s 10.04 release. However, as several blogs (see links below) pointed out there are a few bumps, e.g. with suspend and resume, or the wireless chip that is able to connect, but doesn&#8217;t want to send or receive data. The bumps were smoothed out by installing a newer kernel (2.6.35-12-generic) from the Ubuntu kernel PPA. The 2.6.35 kernel is the one that will be used in the next Ubuntu release and the PPA contains packages that make this kernel run in the present release as well. With that kernel, suspend and hibernate run well, as well as most Fn function keys. In fact, the only one that doesn&#8217;t seem to work is Fn+F3 for microphone mute. I had to turn on the bluetooth module in Windows before it showed up in Ubuntu (as noted by several blogs). At the moment, the things that don&#8217;t work correctly are:<br />
- The microphone doesn&#8217;t record (neither in the sound recorder, nor when using Skype). Sometimes it shows some activity if the mic-volume slider is moved to about 25%, but I couldn&#8217;t get that to work reliably.<br />
- The combined mic/headphone jack doesn&#8217;t mute the speakers if a pair headphones is plugged in (neither is any sound heard through the headphones).<br />
Maybe a newer ALSA release in the upcomming Ubuntu 10.10 will remedy these problems.</p>
<p>I was pleasantly surprised by the fact that using the open source radeon driver (installed by default) for the AMD/ATI graphics card worked out of the box, including Compiz 3D desktop fancy stuff. The VGA out also worked perfectly when I hooked it up to my Sony Bravia TV. Xorg&#8217;s RandR detected it and I could choose between an extended desktop or a clone setup. </p>
<p>As I already mentioned, I&#8217;m a trackpoint user, so I wanted to disable the touchpad, especially since the two buttons for it are located at the front edge of the laptop and are easily pressed when the device sits on your lap and you&#8217;ve got your knees pulled up.<br />
Secondly I enabled wheel emulation for the trackpoint. Now, if I click and hold the middle &#8216;mouse&#8217; button and push the trackpoint in a certain direction it acts as a scroll wheel. To achieve this I created the file <code>/usr/lib/X11/xorg.conf.d/20-thinkpad.conf</code> (EDIT: for Ubuntu 10.10 this file should be located in <code>/usr/share/X11/xorf.conf.d/</code>) with the following contents:</p>
<pre>
Section "InputClass"
	Identifier "Trackpoint Wheel Emulation"
	MatchProduct "Trackpoint"
	MatchDevicePath "/dev/input/dev*"
	Driver "evdev"
	Option "EmulateWheel" "true"
	Option "EmulateWheelButton" "2"
	Option "Emulate3Buttons" "3"
	Option "XAxisMapping" "6 7"
	Option "YAxisMapping" "4 5"
EndSection
</pre>
<p>All in all I&#8217;m very happy with the X100e. It&#8217;s a small but sturdy laptop with an excellent screen and a great keyboard. </p>
<p>Some links:<br />
- <a href="http://netbooked.net/netbook-reviews/review/lenovo-thinkpad-x100e-review/">An excellent review of the Lenovo Thinkpad X100e</a><br />
- <a href="http://www.anandtech.com/show/3886/lenovo-thinkpad-x100e">A recent review at AnandTech</a><br />
- <a href="https://launchpad.net/~kernel-ppa/+archive/ppa">Ubuntu kernel PPA</a><br />
- <a href="http://www.thinkwiki.org/wiki/Category:X100e">ThinkWiki page for the X100e</a>, has lots of info on running Linux on this laptop.<br />
- <a href="http://justinsomnia.org/2010/02/ubuntu-on-a-lenovo-thinkpad-x100e/">A blog about installing Ubuntu Linux on the X100e</a>, the problems mentioned in that post and its comments have now been solved (if you install the 2.6.35 kernel from the PPA). I tried the <code>gpointing-device-settings</code> package for some time (to get the trackpoint scroll functionality to work), but its settings didn&#8217;t survive across reboots or even after hibernating, so I removed it again.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2010/09/12/lenovo-thinkpad-x100e-and-ubuntu-10-04/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Linux, the Logitech Trackman Marble and emulating a scroll wheel</title>
		<link>http://blog.karssen.org/2010/09/11/linux-the-logitech-trackman-marble-and-emulating-a-scroll-wheel/</link>
		<comments>http://blog.karssen.org/2010/09/11/linux-the-logitech-trackman-marble-and-emulating-a-scroll-wheel/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 22:10:31 +0000</pubDate>
		<dc:creator>LCK</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[hardware]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://blog.karssen.org/2010/09/11/linux-the-logitech-trackman-marble-and-emulating-a-scroll-wheel/</guid>
		<description><![CDATA[At work I recently came across a trackball. It was about to be thrown away and since I&#8217;d never really used one I decided to take it home and try it out. It&#8217;s a Logitech Trackman Marble, still for sale on Logitech&#8217;s website. The trackball features four buttons: two large ones for left and right-clicking [...]]]></description>
			<content:encoded><![CDATA[<p>At work I recently came across a trackball. It was about to be thrown away and since I&#8217;d never really used one I decided to take it home and try it out. It&#8217;s a Logitech Trackman Marble, still for sale on Logitech&#8217;s website. </p>
<p>The trackball features four buttons: two large ones for left and right-clicking and to smaller ones that work as back and forward buttons in Firefox, for example.</p>
<p>After plugging it into my PC it was instantly recognised by X (I&#8217;m using Ubuntu 10.04). There&#8217;s no middle mouse button, but that can be emulated by clicking the left and right mouse buttons at the same time (something I&#8217;ve been use to on older laptops, and, well, even from the time that some of the mouses I owned only had two buttons). However, I did miss my scroll wheel. A quick search on the Internet brought me to Rob Meerman&#8217;s website where he explains a lot about the Trackman and how it works in X. He even has <a href="http://www.robmeerman.co.uk/unix/xinput#enabling_emulation_ubuntu_1004">a special section on Ubuntu 10.04</a>. In short it comes down to these commands:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xinput set-int-prop <span style="color: #ff0000;">&quot;Logitech USB Trackball&quot;</span> <span style="color: #ff0000;">&quot;Evdev Wheel Emulation Button&quot;</span> <span style="color: #000000;">8</span> <span style="color: #000000;">8</span>
xinput set-int-prop <span style="color: #ff0000;">&quot;Logitech USB Trackball&quot;</span> <span style="color: #ff0000;">&quot;Evdev Wheel Emulation&quot;</span> <span style="color: #000000;">8</span> <span style="color: #000000;">1</span></pre></div></div>

<p>Unfortunately the changes made by these commands are not persistent across reboots. I&#8217;ll try to fix that later.</p>
<p>EDIT: To add middle mouse button emulation and horizontal scrolling (thanks to rejistania below) run:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xinput set-int-prop <span style="color: #ff0000;">&quot;Logitech USB Trackball&quot;</span> <span style="color: #ff0000;">&quot;Evdev Middle Button Emulation&quot;</span> <span style="color: #000000;">8</span> <span style="color: #000000;">1</span>
xinput set-prop <span style="color: #ff0000;">&quot;Logitech USB Trackball&quot;</span> <span style="color: #ff0000;">&quot;Evdev Wheel Emulation Axes&quot;</span> <span style="color: #000000;">6</span> <span style="color: #000000;">7</span> <span style="color: #000000;">4</span> <span style="color: #000000;">5</span></pre></div></div>

<p>END EDIT</p>
<p>Regarding the use of a trackball compared to an ordinary mouse my experiences so far have been very positive. It didn&#8217;t take me a lot of time to get used to it. Also precision placement of the pointer doesn&#8217;t seem to be more difficult that with a regular mouse. So for now my wireless Logitech mouse can take a holiday <img src='http://blog.karssen.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> . The nicest think about the trackball is the fact that you don&#8217;t have to move the whole device. So it&#8217;s less &#8216;weight lifting&#8217;. Also, the fact that the ball (in combination with the small button) is the scroll wheel, makes for a relatively heavy wheel without much friction, so scrolling large distances can simply be done by giving the ball a good spin. Nice!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.karssen.org/2010/09/11/linux-the-logitech-trackman-marble-and-emulating-a-scroll-wheel/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

