Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 - script.py... and echo the process id of the program once started.

Likewise I want to echo stopping service - script.py... 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/script.py as an OS service."
author "Corey F. - 12/2011"

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

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

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

exec /home/lv_admin/applications/systems/script.py
respawn

I think I need the command 2534 status to get the processid and last known state of the service (as explained here: http://upstart.ubuntu.com/getting-started.html ) 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

1 Answer 1

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

 
discard

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.