System Initialization (old stuff)
System V init (sysvinit)
is based on a runlevel concept. The SysV
init
examines /etc/inittab for
a line that sets a default runlevel:
id:3:initdefault:
If there is no such line, user is prompted to enter runlevel
value manually. The initialization process is synchronous,
i.e., the next task wouldn't start until the current one is finished.
The init
daemon runs scripts in /etc/init.d dir.
The order of execution is defined by the symlinks in /etc/rc.d
dir. The names of these symlinks are interpreted as follows: first letter
S means that the script must be invoked during startup, first
letter K - during shutdown, digits set the order of invocation.
By modern standards sysvinit is slow and resource-consuming.
It is also inconvenient for the desktop systems, that require fast and
reliable interaction with USB devices, removable storage, etc.
Upstart
is an event-based system, that starts and
stops services and
tasks asynchronously, and supervises them
while OS is running. The time and the order [of the specific service start]
depend on a set of conditions (like the presence of processes that a service
depends upon).
The main Upstart programs are the init
(daemon)
and the initctl
(it starts
and stops init jobs, sends signals, and queries
the status of jobs. The Upstart init
daemon tries to
perform tasks in parallel to finish the boot procedure as fast as possible.
Upstart service config files (equivalent of Sys V init
scripts) are in /etc/init dir. Here is an example of a simple
service config file for a permanently running daemon (server application
listening on some tcp port); this config file provides start/stop and auto
restart in case of an abnormal exit:
# htpasd - this server app provides ... ...; description "third-party daemon" start on (net-device-up and local-filesystems) stop on runlevel [!2345] expect fork respawn exec htpasd
You can find details using man 5 init
and multiple
examples in /etc/init (if your system is Upstart-based,
of course).
Classical /etc/inittab is not neccessary any more, though it can be present. To set the default runlevel, edit
/etc/init/rc-sysinit.conf
Upstart consists of 5 packages:
upstart
init
daemon, initctl
;
upstart-logd
logd
daemon and job definition file for
logd
;
upstart-compat-sysv
SysV job definition files and utilities: reboot
,
runlevel
, shutdown
, telinit
;
startup-tasks
job definition files for system startup tasks;
system-services
job definition files for tty services;
See usage examples in
initctl
.
Though Upstart is backward-compatible with sysvinit and runs
the old-style scripts unmodified, you should not rely on the old tools like
chkconfig
,
rc-sysv-conf
, ntsysv
- they control old-style
services only. The new-style services are being started and
stopped if/when the pre-defined conditions are met. To prevent the start
of a new-style service during system start, change the extension of the
corresponding config file, e.g.:
cd /etc/init
mv dovecot.conf dovecot.disabled
stop dovecot
You also have such options as moving the service .conf file
to some dir, or totally deleting it (unwise), or removing the
appropriate software pkg from the system (should be carefully considered).
The last cmd (stop
) is required if the service is currently
running.
Runlevel
defines the certain system's state, characterized by the set of the running services (daemons). It is a System V paradigm. The last Ubuntu releases emulate runlevels for backward compatibility with the old-style scripts and for compatibility with the third-party applications intended for other distributions.
There could be up to 8 runlevels, but only 3 are mandatory:
RL | Name | Description |
---|---|---|
0 | Halt | Modern x86 computers usually power off when run level 0 is reached; older x86, and some different architectures display a message and stay on; |
1 | Single user mode | In run level 1 no daemons (services) are started; GRUB / Recovery mode (single user mode) explains how to boot into a single user mode; |
6 | Reboot | This is like runlevel 0 except a reboot is issued at the end of the sequence instead of a power off; |
The other runlevels are treated differently by different systems. It's supposed, that for each supported runlevel, /etc/inittab has a description of what should be done when the system switches from one runlevel to another.
RL | Description |
---|---|
2 | Full scale multi-user mode without GUI; default runlevel for Red Hat/Fedora server, Ubuntu, Debian (see note below); |
3 | Same as previous plus NFS (?); default runlevel for Arch Linux, Gentoo, Slackware; |
4 | Usually undefined; |
5 | Full scale multi-user mode with GUI, i.e., the most appropriate mode for the desktop systems; default runlevel for Mandriva Linux, SUSE Linux, Red Hat/Fedora desktop; |
In Ubuntu/Debian runlevels 2, 3, 5 are all the same (multi-user, GUI). To check the current runlevel:
runlevel
or
who -r