How do I debug Upstart scripts?

Upstart logs your service execution in a log file by the same name in /var/log/upstart/your-service-name.log. It should be helpful.


All of the following information (and quite a lot more useful Upstart help) is from The Upstart Cookbook. Section 18 covers debugging. http://upstart.ubuntu.com/cookbook/#debugging

In this specific case of tracing a "script" stanza of an Upstart job you should add the following lines right below the word "script":

exec 2>>/dev/.initramfs/myjob.log
set -x

The reason for the odd location is that /dev/.initramfs/ is available in very early boot, before the root file system has been loaded, and continues to be available after boot. I'm guessing with apport, however, you probably don't need to use that path. Still, it's nice to know the option.

It should also be noted that all scripts are run with set -e so any command that fails will exit the script entirely. Which makes sense, as one should be very careful when running scripts as root.

I highly recommend consulting the Upstart Cookbook linked above in general for anyone working with Upstart jobs.