Why isn't my upstart service starting on system boot?

Solution 1:

I would recommend increasing the verbosity of the job, e.g. by using pre-start/post-start entries.

pre-start script
  logger "pre-start for myprog"
end script

post-start script
  logger "post-start for myprog"
end script

# and for PMS itself:
script
  logger "just before executing PMS"
  exec /home/administrator/pms-current/PMS.sh
end script

Further information at http://upstart.ubuntu.com/cookbook/

Also have a look at http://upstart.ubuntu.com/wiki/Debugging

Solution 2:

What's probably happening here is that pms is starting before your network adapters come up, and probably before even the loopback adapter (lo). Assuming we're talking about PS3 Media Server, it's a networked service and it probably doesn't like starting up with no interfaces available.

Try changing your start on criteria to:

start on filesystem and net-device-up IFACE!=lo

Meaning, start after any "real" network interface is up. However, that might not be ideal, if eth0 is the next interface up, PMS starts, but you really want PMS to use wlan0, that won't do. The service will start but it might not have been able to pick the interface you wanted it to listen on. Assuming you know the interface you're going to stream over and it won't be changing, I would hardcode it into the job, e.g.:

start on filesystem and net-device-up IFACE=wlan0

On Oneiric (11.10), you can use the event static-network-up to wait for all statically configured devices. Which is nice because it allows you to write network-dependent jobs without hardcoding an interface. [Note: by "all statically configured devices", I'm referring to using /etc/network/interfaces instead of NetworkManager. It does not mean static in the sense of static IP vs. DHCP.]

Solution 3:

From examining your syslog the pms process starts with no errors but then after a short while its goal is changed from start to stop meaning it is killed.

This is slightly strange because you have added the repsawn clause so it should attempt to start again after it is stopped but it never does. So I'm guessing you removed the respawn clause.

Between the pms service starting and stopping only 2 services are started ufw and network-interface (eth0), and 1 is started udev-fallback-graphics.

It seems that you process pms is being started in parallel. Unfortunately the upstart documentation is a little bit hazy on the exact differences between start on ... vanilla and start on starting ... and start on started ....

Try changing your startup stanza to

start on started networking

or just too

start on net-device-up IFACE=eth0

The log output is slightly strange as the net-device-up event comes much later but pms starts before it.

This should ensure that your process only starts once all networking set up is finished i.e. the job has not only started but finished.

Also do not trust log output completely, early in the boot process logging output to any file does not always work. See the answer in Debugging Upstart

Solution 4:

Managed to fix similar problem by using start on runlevel instead:

start on runlevel [2345]