Boot Up
From: https://help.ubuntu.com/community/UbuntuBootupHowto



UbuntuBootupHowto


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
  1. /etc/init is where the upstart init configs live. While they are not scripts themselves, they essentially execute whatever is required to replace sysvinit scripts.
  2. /etc/init.d is where all the traditional sysvinit scripts and the backward compatible scripts for upstart live. The backward compatible scripts basically run service myservice start instead of doing anything themselves. Some just show a notice to use the "service" command.
  3. /etc/init/rc-sysinit.conf controls execution of traditional scripts added manually or with update-rc.d to traditional runlevels in /etc/rc*
  4. /etc/default has configuration files allowing you to control the behaviour of both traditional sysvinit scripts and new upstart 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 Note: Upstart method will show both traditional and upstart services.
Adding a Service to Default runlevels # Traditional update-rc.d apache2 defaults
  1. Upstart: there is no concept of runlevels, everything is event driven with dependencies. You would add an upstart config to /etc/init and potentially source a config file in /etc/default to allow users to override default behaviour.

Removing a Service from Default runlevels # Traditional - Something along the lines of rm /etc/rc*/*myscript
  1. Upstart: If no config is available in /etc/default, edit config in /etc/init

Other Upstart Commands
Controlling Services - interchangeable with the "service" command
  1. initctl - can use in place of "service" with the commands below. Run: initctl help.
  2. start - start a service
  3. stop - stop a service
  4. reload - sends a SIGHUP signal to running process
  5. restart - restarts a service without reloading its job config file
  6. status - requests status of service

Rebooting and Powering off the system
  1. halt - shutdown the system then power off
  2. poweroff - shutdown the system then power off
  3. reboot - reboot the system
  4. shutdown - bring the system down

Misc Upstart Commands - you generally don't use these directly
  1. init - Upstart process management daemon
  2. runlevel - Backward compatibility with traditional runlevels
  3. telinit - Backward compatibility with traditional runlevels
  4. upstart-udev-bridge - Bridge between upstart and udev

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 " # Stanzas # Stanzas control when and how a process is started and stopped # See a stanza list here: # 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:
    1. 'initctl emit starting-postgresql’ in /etc/init.d/postgresql just before the service is started
    2. ‘initctl emit started-postgresql’ just after
    3. As well as ‘initctl emit stopping-postgresql’ and ‘initctl emit stopped-postgresql'
    4. 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 Links
  1. update-rc
  2. Sdock
  3. s-sysvinit
  4. UpstartHowto