<?xml version="1.0" encoding="utf-8" ?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Fun with ones and zeros - daemontools</title>
<subtitle>Barry&#039;s notes on computer software and hardware</subtitle>
<link href="/blog/tags/daemontools"></link>
<updated>2026-04-17T15:14:49-07:00</updated>
<id>urn:uuid:5c8a7fe9-0efb-e3c2-d2b2-f5f0d17a0c3a</id>
<entry>
<title>Daemontools mishap</title>
<link href="/blog/entries/daemontools-mishap"></link>
<id>urn:uuid:ac0d4982-9eb5-1a22-eef8-013c879fc460</id>
<updated>2008-02-11T14:01:00-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">&lt;p&gt;While working on my &lt;a href=&quot;https://DiskCompare.com&quot;&gt;DiskCompare.com&lt;/a&gt; website I had a weird problem with &lt;a href=&quot;http://cr.yp.to/daemontools.html&quot;&gt;daemontools&lt;/a&gt;.  The Django process I had running under daemontools became unresponsive, it wouldn&#039;t shutdown normally with &lt;code&gt;svc -d&lt;/code&gt;, and after &lt;code&gt;kill -9&lt;/code&gt; and restarting, it still wouldn&#039;t respond - it just seemed hung up or frozen.  No messages in &lt;code&gt;/var/log/messages&lt;/code&gt;, but running the service manually outside of daemontools worked fine.  What the heck?&lt;/p&gt;
&lt;p&gt;I had the service also setup to run &lt;code&gt;multilog&lt;/code&gt;, 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 &lt;code&gt;multilog&lt;/code&gt; process that was really hung up, since it couldn&#039;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.&lt;/p&gt;
&lt;p&gt;Simply correcting the permissions of the &lt;code&gt;log&lt;/code&gt; directory cleared the jam and things took off again.  So if you&#039;re seeing strange behavior with &lt;code&gt;daemontools&lt;/code&gt;, that&#039;s one area to check out.&lt;/p&gt;</content>
</entry>
<entry>
<title>Doing things the DJB way
</title>
<link href="/blog/entries/thedjbway"></link>
<id>urn:uuid:6279810e-c975-c975-27c2-8f0b61d5ae40</id>
<updated>2006-01-16T12:11:00-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">
&lt;p&gt;
While doing a bit more searching for daemontools info, found
&lt;a href=&quot;http://thedjbway.org&quot;&gt;the djb way&lt;/a&gt; website, which
has some nice writeups on &lt;a href=&quot;http://thedjbway.org/daemontools.html&quot;&gt;daemontools&lt;/a&gt;
and &lt;a href=&quot;http://thedjbway.org/djbdns.html&quot;&gt;djbdns&lt;/a&gt; (which I also use a fair amount).
&lt;/p&gt;



</content>
</entry>
<entry>
<title>Running a SCGI server under daemontools</title>
<link href="/blog/entries/scgi_daemon"></link>
<id>urn:uuid:6dd34d85-8134-bfeb-c9ab-76301edc761d</id>
<updated>2006-01-16T09:55:00-08:00</updated>
<author><name>Barry Pederson</name>
<email>bp@barryp.org</email>
</author>
<content type="html">
&lt;p&gt;
Yesterday, I was working on &lt;a href=&quot;http://barryp.org/blog/python/pyblosxom_scgi.html&quot;&gt;Running PyBlosxom through SCGI&lt;/a&gt;, 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.  
&lt;a href=&quot;http://cr.yp.to/daemontools.html&quot;&gt;Daemontools&lt;/a&gt; seems like an easy way to set this up, I already had it
running on my server.
&lt;/p&gt;
&lt;p&gt;
Daemontools runs a process called &lt;a href=&quot;http://cr.yp.to/daemontools/svscan.html&quot;&gt;&lt;code&gt;svscan&lt;/code&gt;&lt;/a&gt; 
that looks for directories in &lt;code&gt;/var/service&lt;/code&gt; (the default when installed through the FreeBSD port) 
that contain an executable named &lt;code&gt;run&lt;/code&gt;.  If &lt;code&gt;svscan&lt;/code&gt;
also finds a &lt;code&gt;log/run&lt;/code&gt; executable in that directory, it starts that too and ties the two together 
with a pipe.  Daemontools includes a &lt;a href=&quot;http://cr.yp.to/daemontools/multilog.html&quot;&gt;&lt;code&gt;multilog&lt;/code&gt;&lt;/a&gt;
program that reads from the pipe (stdin), and writes out and rotates log file for you automatically.
&lt;/p&gt;
&lt;p&gt;
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
&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;mkdir /tmp/pyblosxom
cd /tmp/pyblosxom

cp ~/config.py .
cp ~/wsgi_app.py .
cp ~/scgi_server.py .
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;
(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)
&lt;/p&gt;
&lt;p&gt;
Next, I came up with a &lt;code&gt;run&lt;/code&gt; script to execute the SCGI server under the &lt;code&gt;www&lt;/code&gt;
userid, with &lt;code&gt;stderr&lt;/code&gt; tied to &lt;code&gt;stdout&lt;/code&gt;.  Daemontools has a 
&lt;a href=&quot;http://cr.yp.to/daemontools/setuidgid.html&quot;&gt;&lt;code&gt;setuidgid&lt;/code&gt;&lt;/a&gt;
program that makes this pretty easy
&lt;/p&gt;

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

&lt;pre&gt;&lt;code&gt;mkdir log
mkdir log/main
chown www:www log/main
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;
And in the &lt;code&gt;log&lt;/code&gt; directory put another tiny &lt;code&gt;run&lt;/code&gt; script.
&lt;/p&gt;

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

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

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

</content>
</entry>
</feed>