Tag/tag.png

Style Cleanup Required
This article does not follow the style standards in the Wiki Guide. More info...

Tag/tag.png

Content Cleanup Required
This article should be cleaned-up to follow the content standards in the Wiki Guide. More info...

# This material should probably be merged with UpstartHowto

Since Ubuntu 6.10 (Edgy Eft)

Since the introduction of Upstart some time in 2006, or more relevantly 9.10 Karmic where most of the system services were converted, the boot process changed somewhat. The following information is tested on 11.04 Natty:

Directories and Configs

Using Services

Please note that generally, you can use either traditional sysvinit scripts and the methods of working with them as well as the new upstart configs and the command: "service" interchangeably. It is however recommended you use the new upstart methods which are both forward and backward compatible.

Starting a Service

# Traditional:
/etc/init.d/myservice start
# Upstart
service myservice start

Stopping a Service

# Traditional: 
/etc/init.d/myservice stop
# Upstart
service myservice stop

Getting a list of Services

# Traditional:
ls /etc/init.d
# Upstart: 
service --status-all

Adding a Service to Default runlevels

# Traditional
update-rc.d apache2 defaults

Removing a Service from Default runlevels

# Traditional - Something along the lines of
rm /etc/rc*/*myscript

Other Upstart Commands

Controlling Services - interchangeable with the "service" command

Rebooting and Powering off the system

Misc Upstart Commands - you generally don't use these directly

Writing Services

The most current reference for job/service definition is available in the man page for init, available by running man 5 init. There are also some very useful pointers in The Upstart Cookbook.

Here is an example of a simple upstart job config: /etc/init/myservice.conf

# myservice - myservice job file

description "my service description"
author "Me <myself@i.com>"

# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Run before process
pre-start script
    [ -d /var/run/myservice ] || mkdir -p /var/run/myservice
    echo "Put bash code here"
end script

# Start the process
exec myprocess

Helpful Tips

  1. initctl list shows new services straight away, service command might not!

  2. Check /var/log/syslog, it will show clues as to what went wrong.

  3. All scripts default to running with errexit (set -e), so any non-zero exit status will cause errors. In pre-start, this means the service won't start.
  4. if you want to fire events from your legacy sysvinit scripts, for example postgres, you can add the following:
    • 'initctl emit starting-postgresql’ in /etc/init.d/postgresql just before the service is started
    • ‘initctl emit started-postgresql’ just after
    • As well as ‘initctl emit stopping-postgresql’ and ‘initctl emit stopped-postgresql
    • Then you can use ‘start on started-postgresql’ and ‘stop on stopping-postgresql’ in your job.

See Upstart Getting Started for more details about upstart.

[For more details about Ubuntu transitioning away from the sysv init system. See upstart.]

List of init scripts

see InitScriptList

UbuntuBootupHowto (last edited 2017-09-10 19:40:48 by ckimes)