The first thing I did was to create a simple job:
task script sleep 5 end script
This job simply blocks for five seconds, which allows me to test whether user jobs are working properly. To use it I saved it to ~/.init/my-test-job.conf, and then started it via start my-test-job.
Unfortunately by default on Ubuntu 11.10, user jobs are disabled, which meant the start command failed with the error:
start: Rejected send message, 1 matched rules; type="method_call", sender=":1.5" (uid=1000 pid=1655 comm="start my-test-job ") interface="com.ubuntu.Upstart0_6.Job" member="Start" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init")
To enable user jobs, I had to edit /etc/dbus-1/system.d/Upstart.conf and change it to:
The original DBus configuration is far more restrictive in what messages it allows to reach Upstart (basically read/write for root and read for everyone else). The above configuration (taken from Upstart's source code) allows any user to control Upstart. This does seem like a security problem, but apparently Upstart can handle user permissions internally.
After making this change, I was able to start my job successfully:
$ start my-test-job my-test-job stop/waiting
Documentation is pretty scarce, but there's a small section in the man page that's worth checking out (search for User Jobs).
Edit:
If you want user job start on stanzas to be honored, check out my more recent blog post about it
Thanks so much for this! You saved me the hassle of figuring it out myself! :D
ReplyDeleteYou saved my life!
ReplyDelete