Linux Start Up
From: https://help.ubuntu.com/community/UbuntuBootupHowto
Ubuntu Bootup Howto
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
/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.
/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.
/etc/init/rc-sysinit.conf
controls execution of traditional scripts added
manually or with update-rc.d to traditional runlevels in /etc/rc*
/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
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
Upstart: If no config is available in /etc/default, edit config in /etc/init
Other Upstart Commands
Controlling Services - interchangeable with the "service" command
- initctl - can use in place of "service" with the commands bellow. Run
initctl help.
- start - start a service
- stop - stop a service
- reload - sends a SIGHUP signal to running process
- restart - restarts a service without reloading its job config file
- status - requests status of service
Rebooting and Powering off the system
- halt - shutdown the system then power off
- poweroff - shutdown the system then power off
- reboot - reboot the system
- shutdown - bring the system down
Misc Upstart Commands - you generally don't use these directly
- init - Upstart process management daemon
- runlevel - Backward compatibility with traditional runlevels
- telinit - Backward compatibility with traditional runlevels
- 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 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
initctl list
shows new services straight away, service command might
not!
- Check
/var/log/syslog
, it will show clues as to what went wrong.
- 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.
- 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
Links
- http://www.wlug.org.nz/update-rc.d%288%29
- http://tinyurl.com/5dock
- http://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit
- UpstartHowto