Running Upstart user jobs on startup

I am running Ubuntu server 11.04. I have created an Upstart user job as described here.

I have the following file at my /home/myuser/.init/sensors.conf:

start on started mysql
stop on stopping mysql


chdir /home/myuser/mydir/project
exec /home/myuser/mydir/env/bin/python /home/myuser/mydir/project/manage.py sensors

respawn

respawn limit 10 90

As myuser I can start, stop, and reload the job fine- it works perfectly:

$ start sensors
sensors start/running, process 1332
$ stop sensors
sensors stop/waiting

The problem is that the job is not starting automatically at boot when mysql starts. After a fresh boot, mysql is running but my sensors job is not.

What's strange, is that although the job doesn't begin on bootup, if I use sudo to restart mysql it does indeed start my job. The following commands are run as myuser from a fresh startup:

$ status sensors
sensors stop/waiting
$ sudo restart mysql
mysql start/running, process 1209
$ status sensors
sensors start/running, process 1229

The documentation for Upstart user jobs is pretty limited. What is the correct technique to have a user job start automatically on startup of the system?

I know I can just throw something in rc.local to start it, or I could move my sensors.conf to /etc/init but I'm curious if there is a way to do it using just Upstart.


Solution 1:

The problem is that user jobs aren't loaded into Upstart until the user creates an Upstart session by running one of the initctl commands.

I've described it in more detail at http://bradleyayers.blogspot.com.au/2012/04/enabling-upstart-user-jobs-to-start-at.html and also written an Upstart job that works around the problem.