Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating an upstart script to execute a python program I've written. When the service is starting I want to echo starting service - and echo the process id of the program once started.

Likewise I want to echo stopping service - when it is being stopped.

I have this so far (remember I'm new to this)...

#Name: script.conf
description "An upstart config to run ~/applications/systems/ as an OS service."
author "Corey F. - 12/2011"

pre-start script
    echo 'starting service -'
end script

post-stop script
    echo 'stopped service -'
end script

start on runlevel [2534]
stop on runlevel [!2534]

exec /home/lv_admin/applications/systems/

I think I need the command 2534 status to get the processid and last known state of the service (as explained here: ) but I'm not sure where to put it...

Also, how would I log upstart event problems to a specific file during this execution of this script.conf upstart file? I need to know if upstart has issues starting the process.

share|improve this question

Okie, a bit old question but lets answer it from completeness sake :-)

Lets say you saved this job in /etc/init/myapp.conf, then the job name would be myapp. Asking for the job status (and process id) would simply be: status myapp (as root) or sudo status myapp in typical Ubuntu user case.

Init errors go to dmesg by default, so doing dmesg | grep "init:" gives you the log. More verbose logging can be enabled by sudo initctl log-priority info. Debug levels more verbose than that will spam and confuse you :-)

Doing sudo stop myapp, sudo start myapp gives you feedback instantly on success, plus the process id. In case you get init: unknown job or such, Upstart has failed parsing the configuration file and exact line and reason can be found from dmesg.

share|improve this answer
what about everything else? Are my runlevels, respawn line, and exec lines ok? – sadmicrowave Jan 24 '12 at 16:39
respawn default to 10 restarts in 5 seconds, so its ok. start on stanza is ok, but stop on is usually written as stop on runlevel [016]. exec line is completely up to the program you wish to run. If your program doesn't expect input, it should be ok. Remember, all scripts and execs are run as root. – Tuminoid Jan 25 '12 at 6:10
Sorry for my ignorance; but, is [016] the runlevel I should use for stop on? or is that just an example where in my case my start and stop runlevels should be the same? i.e. stop on runlevel [2534]. – sadmicrowave Jan 25 '12 at 19:27
Runlevels 2, 3, 4, 5 generally mean "booting up" and 0, 6 "going down", 1 being "single user mode" (console only). So you want your service to start when booting and you want it to quit when shutting down. – Tuminoid Jan 25 '12 at 22:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.