Upstart is a ridiculously easy way to turn your scripts into daemons. Take this python script:

/home/myuser/ez_daemon.py:

import time
while 1:
    print("I'm a daemon!")
    time.sleep(1)

We’re going to turn it into a daemon with a single line:

/etc/init/ez_daemon.conf:

exec python /home/myuser/ez_daemon.py

And that’s it!

  • sudo start ez_daemon
  • sudo tail -f /var/log/upstart/ez_daemon.log
  • sudo stop ez_daemon

You can do this for any program, and it’s how Ubuntu and Fedora start most daemons.

Here’s a more complete example:

author "Graham King <graham@gkgk.org>"
description "uwsgi server for example.com"

start on (static-network-up and started mysql)
stop on shutdown

console log
respawn
respawn limit 10 5

setuid www-data
setgid www-data

env PYTHONPATH=/srv/example/src/example/

exec /srv/example/bin/uwsgi \
--virtualenv=/srv/example/ \
--module=example.django_wsgi  \
--http=127.0.0.1:8001

Each line is called a stanza, and they are documented in the Upstart cookbook.

It’s clear, it’s easy, and it works. And that makes me happy.