How do I debug Upstart scripts?

For some reason I’m getting an error during apport upgrades, the cause of which is

% sudo service apport start
start: Job failed to start

Under sysvinit, I could debug this kind of problem by running eg

sudo sh -x /etc/init.d/whatever start

but that doesn’t seem to map over to Upstart. What should I try next?

It turns out there is a workaround that will let the install proceed. But I’m still interested in the general question of how one would trace the script.

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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.

Solution 2

All of the following information (and quite a lot more useful Upstart help) is from The Upstart Cookbook. Section 18 covers 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.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply