January 17, 2019

Controlling Ubuntu's and Fedora's Upstart (the init replacement) - page 2

Controlling Startup Events

  • May 13, 2009
  • By Juliet Kemp

You can also set scripts to run before and after the start of a job:

pre-start exec echo "Starting jobname"

post-start script
echo "Started jobname"
touch /var/run/jobname
end script

pre-stop and post-stop work in exactly the same way.


To choose where the output should go, use the console stanza.

console output

sends the output to /dev/console, while none sends it to /dev/null. The default is logged which sends it to the logger; you can also set it to owner, in which case the process becomes the owner of the console and can receive input from the keyboard.


As in the runlevel 3 script above, you can start on particular runlevels, on the startup event, or in response to another job, e.g.

start on started cupsd

would start this service when cupsd starts. If you want to start or stop a service manually, you can use the start and stop commands (usually found in /sbin/):

start servicename
stop servicename

You can also get the status of a job with status servicename.


Finally, you can list all jobs with initctl list, and emit a custom event with initctl emit eventname. So if we have a job which runs after a ping event:

on ping
exec echo "ping"
console output

it can be run with initctl emit ping, and the console will show this output:




There are various further improvements planned to upstart, including a scheduler so that events can be generated at specific intervals or at particular times, and the ability to react to an event caused by the change of a file or directory. There's development information available if you're interested in following or helping out with the development. The Upstart wiki may also be helpful for both users and developers.

Most Popular LinuxPlanet Stories