<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>Fun with ones and zeros - daemontools</title>
<description><![CDATA[Barry's notes on computer software and hardware]]></description>
<link>/blog/tags/daemontools</link>
<lastBuildDate>Fri, 17 Apr 2026 15:14:49 -0700</lastBuildDate>
<item>
<title>Daemontools mishap</title>
<link>/blog/entries/daemontools-mishap</link>
<pubDate>Mon, 11 Feb 2008 14:01:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[<p>While working on my <a href="https://DiskCompare.com">DiskCompare.com</a> website I had a weird problem with <a href="http://cr.yp.to/daemontools.html">daemontools</a>.  The Django process I had running under daemontools became unresponsive, it wouldn't shutdown normally with <code>svc -d</code>, and after <code>kill -9</code> and restarting, it still wouldn't respond - it just seemed hung up or frozen.  No messages in <code>/var/log/messages</code>, but running the service manually outside of daemontools worked fine.  What the heck?</p>
<p>I had the service also setup to run <code>multilog</code>, and it turns out that I had mistakenly changed the ownership of the log directory it was supposed to be writing to.  My guess is that it was the <code>multilog</code> process that was really hung up, since it couldn't write to the files it wanted to, and that my Django processes were then blocked because the pipe between them and multilog  was full.</p>
<p>Simply correcting the permissions of the <code>log</code> directory cleared the jam and things took off again.  So if you're seeing strange behavior with <code>daemontools</code>, that's one area to check out.</p>]]></description>
</item>
<item>
<title>Doing things the DJB way
</title>
<link>/blog/entries/thedjbway</link>
<pubDate>Mon, 16 Jan 2006 12:11:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[
<p>
While doing a bit more searching for daemontools info, found
<a href="http://thedjbway.org">the djb way</a> website, which
has some nice writeups on <a href="http://thedjbway.org/daemontools.html">daemontools</a>
and <a href="http://thedjbway.org/djbdns.html">djbdns</a> (which I also use a fair amount).
</p>



]]></description>
</item>
<item>
<title>Running a SCGI server under daemontools</title>
<link>/blog/entries/scgi_daemon</link>
<pubDate>Mon, 16 Jan 2006 09:55:00 -0800</pubDate>
<author>bp@barryp.org (Barry Pederson)</author>
<description><![CDATA[
<p>
Yesterday, I was working on <a href="http://barryp.org/blog/python/pyblosxom_scgi.html">Running PyBlosxom through SCGI</a>, but
during that time, I was running the SCGI server by hand in a console window.  
Once it was working I needed to arrange a way to run this in a more permanent fashion.  
<a href="http://cr.yp.to/daemontools.html">Daemontools</a> seems like an easy way to set this up, I already had it
running on my server.
</p>
<p>
Daemontools runs a process called <a href="http://cr.yp.to/daemontools/svscan.html"><code>svscan</code></a> 
that looks for directories in <code>/var/service</code> (the default when installed through the FreeBSD port) 
that contain an executable named <code>run</code>.  If <code>svscan</code>
also finds a <code>log/run</code> executable in that directory, it starts that too and ties the two together 
with a pipe.  Daemontools includes a <a href="http://cr.yp.to/daemontools/multilog.html"><code>multilog</code></a>
program that reads from the pipe (stdin), and writes out and rotates log file for you automatically.
</p>
<p>
To get PyBlosxom/SCGI running under this, started by making a temporary directory, and copying in the 
three files needed to run PyBlosxom through SCGI
</p>

<pre><code>mkdir /tmp/pyblosxom
cd /tmp/pyblosxom

cp ~/config.py .
cp ~/wsgi_app.py .
cp ~/scgi_server.py .
</code></pre><p>
(The first two files come from the PyBlosxom distribtution (the first one is customized).  The third
file is the one I came up with yesterday)
</p>
<p>
Next, I came up with a <code>run</code> script to execute the SCGI server under the <code>www</code>
userid, with <code>stderr</code> tied to <code>stdout</code>.  Daemontools has a 
<a href="http://cr.yp.to/daemontools/setuidgid.html"><code>setuidgid</code></a>
program that makes this pretty easy
</p>

<pre><code>#!/bin/sh
exec 2&gt;&amp;1
exec setuidgid www ./scgi_server.py
</code></pre><p>
Next, made a <code>log</code> subdirectory, a <code>log/main</code> subdirectory
to hold the actual log files (owned by <code>www</code>).
</p>

<pre><code>mkdir log
mkdir log/main
chown www:www log/main
</code></pre><p>
And in the <code>log</code> directory put another tiny <code>run</code> script.
</p>

<pre><code>#!/bin/sh
exec setuidgid www multilog t ./main
</code></pre><p>
Finally, made both <code>run</code> scripts executable, and moved the whole thing
into <code>/var/service</code>
</p>

<pre><code>chmod +x run
chmod +x log/run
cd ..
mv pyblosxom /var/service
</code></pre><p>
<code>svscan</code> sees the new directories within a few seconds, starts up both
run scripts automatically, and you're in business.  See the current contents
of the log with:
</p>

<pre><code>cat /var/service/pyblosxom/log/main/current
</code></pre><p>Stop and restart the server with the Daemontools 
   <a href="http://cr.yp.to/daemontools/svc.html"><code>svc</code></a> utility:
</p>
<pre><code>cd /var/service
svc -d pyblosxom ; svc -u pyblosxom
</code></pre>

]]></description>
</item>
</channel>
</rss>