Use daemontools to keep Pylons applications running

WARINING - THIS IS WORK IN PROGRESS - DON'T RELY ON THIS YET. Daemontools is a little utility to help keeping services running. (It's not related to the Windoze tools that mounts CD ISO images.) Using the following configuration it's easy to keep a Pylons application running with it and restart it if it dies. On Debian you can install the daemontools software using:
$> aptitude install daemontools
Create a user for your service:
$> adduser myapp
Service definitions are stored in /etc/service. Create a directory for your application there (e.g. "/etc/service/myapp/"). Inside the new directory create a file called "run" containing:
#!/bin/sh
export PYTHON_EGG_CACHE=/home/myapp/.python-eggs
cd /home/myapp
exec setuidgid myapp /home/myapp/bin/paster serve /home/myapp/foobar.ini
This "run" script runs the Pylons application in the context of the "myapp" user you created before. The call is just the "paster serve foobar.ini" call you always use to start your Pylons application with the Paster web server. The interesting part is that "paster" is run from "/home/myapp/bin/paster". This helps if you run your application in a "virtualenv" environment. Make it executable:
$> chmod a+rx /etc/service/myapp/run
Before you start your service you should create a log directory and create a "run" file there, too (e.g. /etc/service/myapp/log/run):
#!/bin/sh
exec 2>&1
exec setuidgid myapp multilog t /home/myapp/daemontools.log
Now try to start your application:
$> supervisorctl restart myapp:paster