Upstart is not seeing my new script

I've added a new script to /etc/init/ called minecraft.conf which contains the script:

start on startup
stop on shutdown
respawn
respawn limit 20 5

script
  export HOME="/root"
  exec /root/minecraft/start.sh 2>&1 >> /var/log/minecraft.log
end script

post-start script
   echo "minecraft started"

When I try start minecraft I get the error: start: Unknown job: minecraft

I've tried running initctl list and my minecraft job is not listed. I've tried running initctl reload-configuration and it doesn't make any difference.

Other jobs listed by initctl list work fine with start, stop and restart.

Why won't upstart see my new script?


Solution 1:

An easy way to check your script syntax is with the following command:

init-checkconf -d /etc/init/service_name.conf

I've found that even with a valid Upstart file if the file didn't exist when the server was booted last I have to reboot the server for Upstart to see the file.

Solution 2:

Check the upstart logs (it's in /var/log/syslog) while reloading the configuration using initctl reload-configuration. If there is a syntax error, it will show up there. That's usually why you cannot use your new upstart configuration.

Solution 3:

I feel kinda dumb... But here it is:

I missed the "end script" stanza from the very end of the upstart script...

post-start script
   echo "minecraft started"

should have been

post-start script
   echo "minecraft started"
end script

I'm not sure why it worked for @schkovich without the end script, though...

Solution 4:

In my case it was an empty author field, like this:

author ""

It worked only after adding something in the quotes.

# initctl reload-configuration

was also throwing /etc/init/servicename.conf:2: Expected token to syslog instead of stdout. Too busy to file a bug report for a dying package.

Solution 5:

Perhaps not applicable to this specifically, but worth mentioning: If you edit a Upstart config file for a service that is running, running restart does NOT reload the configuration. You have to run stop and start to have new changes take effect.

http://upstart.ubuntu.com/cookbook/#restart