tracd with upstart on Ubuntu

After spending too many hours trying to get tracd running as a daemon on Ubuntu 10.04 I might as well share my experiences. At first I begun with  some init.d scripts I found googling for tracd init.d. The problem with them was that they were made to run tracd as root which frankly didn’t feel that great. I tried to modify them to use the –user/–chuid options to no avail. In the end I understood that the problem was not those options but that the pid file I was trying to use with the tracd command for some reason couldn’t be written.

These mishaps wasn’t only bad as I therefor started fiddling with upstart. upstart is a much more pleasant experience than classical init scripts. All I had to do was to create the file

/etc/init/tracd.conf

and put

description "tracd server"
author "KO"

start on startup
stop on shutdown

expect daemon

script
        exec sudo -u www-data /usr/bin/tracd --daemonize --port=8000 \
	--hostname=127.0.0.1 -s /path/to/trac/project
end script

in it.

The key here was the expect daemon stanza which saved my day. After that you can use start|stop|status processname like:

sudo start tracd

Now you might wonder why I wanted to run tracd as a daemon. I was about to switch to nginx on the server running trac and the daemon way seemed the easiest.