1

I'm trying to set up an Ubuntu (12.04 LTS) upstart script to manage Trac's built in web server as an upstream server for nginx.

Here is my init script /etc/init/tracd.conf. I used http://codebyko.se/2010/11/26/tracd-with-upstart-on-ubuntu/ (first and only google result for 'upstart' and 'tracd') as a starting point:

description "Tracd Web Server"

start on startup
stop on shutdown

expect daemon

exec sudo tracd -d -p 8000 -b 192.168.1.2 --user=www-data --group=www-data /trac/proj

Whenever I run this through sudo service tracd start or sudo service tracd stop, it simply hangs and never returns. sudo service tracd status returns "tracd start/killed, process 748". The upstart log /var/log/upstart/tracd.log contains no information, nor does syslog.

If I simply copy and paste sudo tracd -d -p 8000 -b 192.168.1.2 --user=www-data --group=www-data /trac/proj on the command line, the server runs fine.

Here is what I've tried:

  • Googled -- hard. Read through Ubuntu's upstart cookbook page and all of the Trac guides: TracInstall, TracNginxRecipe, TracStandalone
  • Use expect fork, expect daemon or omit the expect line entirely.
  • Use script/end script block around the exec line.
  • Use setuid www-data/setgid www-data.
  • Use sudo -u www-data and even sudo su www-data -c "..."
  • Created a www-data writable dir /var/run/trac/ and specified --pidfile=/var/run/trac/tracd.pid.
  • Examine output from sudo -u www-data env to see if there are any special environment variables from command line, because it's running fine when executed from the shell. Trac doesn't appear to rely on any environment variables.
  • Used the much more verbose, but identical command: sudo /usr/bin/python /usr/local/bin/tracd --daemonize --port=8000 --hostname=192.168.1.2 --user=www-data --group=www-data /trac/proj
  • Checked for zombie tracd daemons with ps -aux | grep trac.

Things I haven't tried:

  • Abandon upstart for an init.d script.

EDIT: Fixed

Removing the --daemonize flag seems to have fixed it. Thanks Mike! Here's my working upstart script:

description "Trac Web Server"

start on startup
stop on shutdown

setuid www-data
setgid www-data

exec tracd -p 8000 -b 192.168.1.2 /trac/proj
jcampbelly
  • 113
  • 6

1 Answers1

2

I don't think you need the sudo since tracd is setting the user/group

description "Tracd Web Server"

start on startup
stop on shutdown


expect daemon

exec tracd -p 8000 -b 192.168.1.2 --user=www-data --group=www-data /trac/proj

If that doesn't work try to set the running user in upstart via setuid and setgid

description "Tracd Web Server"

start on startup
stop on shutdown

setuid www-data
setgid www-data

expect daemon

exec tracd -p 8000 -b 192.168.1.2 /trac/proj

EDIT

remove the -d flag.. upstart you cannot run something as a daemon it needs to act like it is running in the foreground

Mike
  • 21,910
  • 7
  • 55
  • 79
  • I tried both, but the problem is the fact that the same command (from `exec ` on) works on the shell, but in a service definition, `sudo service tracd start` or `stop` just hangs. – jcampbelly Dec 31 '12 at 04:50
  • ohh i see the problem.. see the edit – Mike Dec 31 '12 at 05:24
  • so the -d flag needs to be removed.. upstart likes things to run in the foreground. It is hanging probably due to the -d flag – Mike Dec 31 '12 at 05:25
  • glad that was the problem – Mike Dec 31 '12 at 06:06