Primary image for The Joy of Upstart

The Joy of Upstart

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

/home/myuser/ez_daemon.py:

exec python /home/myuser/ez_daemon.py
And that&#8217;s it! <ul> <li>sudo start ez_daemon</li> <li>sudo tail -f /var/log/upstart/ez_daemon.log</li> <li>sudo stop ez_daemon</li> </ul> You can do this for any program, and it&#8217;s how Ubuntu and Fedora start most daemons. Here&#8217;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.
Graham King

About the author

Graham King

Graham's life has revolved around growing software since age 12. After many years of C, and more of Java, Graham fell in love with Python in 2003 and Django in 2005. Most of his previous career …

Graham is no longer active with Lincoln Loop, but you can find him at https://www.darkcoding.net.