1runlevel(7) Miscellaneous Information Manual runlevel(7)
2
3
4
6 runlevel - event signalling change of system runlevel
7
9 runlevel RUNLEVEL=RUNLEVEL PREVLEVEL=PREVLEVEL [ENV]...
10
12 This page describes the runlevel Upstart event, and the general imple‐
13 mentation of runlevels in the Upstart system. For the runlevel tool,
14 see runlevel(8)
15
16 The runlevel event
17 The runlevel event signals a change of system runlevel. The new system
18 runlevel is given in the RUNLEVEL argument, and the previous system
19 runlevel in the PREVLEVEL argument (which may be empty).
20
21 Additional environment may follow these depending on the runlevel, and
22 the tool that emitted the event. The shutdown(8) tool will supply an
23 INIT_HALT variable set to either HALT or POWEROFF when called with -H
24 or -P respectively.
25
26 Runlevels
27 Runlevels are a concept from UNIX® System V used by the init(8) daemon
28 or other system initialisation system to define modes of system opera‐
29 tion.
30
31 Eight runlevels are permitted, the first seven are numbered 0-6 and the
32 eighth is named S or s (both are permitted).
33
34 Services and other system components are said to exist in one or more
35 runlevels. When switching from one runlevel to another, the services
36 that should not exist in the new runlevel are stopped and the services
37 that only exist in the new runlevel are started.
38
39 This is performed by the /etc/init.d/rc script executed on a change of
40 runlevel (by jobs run on the runlevel event in the Upstart system).
41 This script examines symlinks in the /etc/rc?.d directories, symlinks
42 beginning K are services to be stopped and symlinks beginning S are
43 services to be started.
44
45 The authorative documentation for this process can be found in the Sys‐
46 tem run levels and init.d scripts section of the Debian Policy Manual.
47 This may be currently found at <http://www.debian.org/doc/debian-pol‐
48 icy/ch-opersys.html#s-sysvinit>
49
50 Runlevels 0, 1 and 6 are reserved. Runlevel 0 is used to halt the sys‐
51 tem and 6 to reboot the system. Runlevel 1 is used to bring the system
52 back down into single-user mode, after which the runlevel will be S.
53
54 System V initialisation in Upstart
55 The compatible implementation of runlevels permits Upstart jobs to be
56 run on the runlevel event that perform the same functionality as the
57 original System V init(8) daemon.
58
59 The /etc/init/rc.conf job is run on the runlevel event, thus receiving
60 the RUNLEVEL and PREVLEVEL environment variables. Its sole job is to
61 execute the /etc/init.d/rc script, passing the new runlevel as an argu‐
62 ment.
63
64 Initial system startup is provided by the /etc/init/rc-sysinit.conf
65 job. This is run on the startup(7) event, and is primarily responsible
66 for running the /etc/init.d/rc script with the special S argument and
67 calling telinit(8) to switch into the default runlevel when done. This
68 also handles the -b, emergency, -s and single kernel command-line
69 options as well as specifying an alternate runlevel on the kernel com‐
70 mand-line.
71
72 Finally the /etc/init/rcS.conf job handles the special case of entering
73 the single-user runlevel and providing a login shell. Once that shell
74 terminates, this restarts the rc-sysinit job to re-enter the default
75 runlevel.
76
77 Implementation of runlevels in Upstart
78 The Upstart init(8) daemon has no native concepts of runlevel, and
79 unlike the System V daemon, makes no attempt to keep track of the cur‐
80 rent runlevel.
81
82 Instead a compatible implementation is provided by the runlevel(8),
83 telinit(8) and shutdown(8) tools supplied with Upstart.
84
85 The telinit(8) and shutdown(8) tools are used by system administrators
86 to change the runlevel, thus they both generate this runlevel event
87 obtaining the value for the PREVLEVEL environment variable from their
88 own environment (the RUNLEVEL variable) or the /var/run/utmp file.
89
90 Additionally they update the /var/run/utmp file with the new runlevel,
91 and append a log entry to the /var/log/wtmp file.
92
93 The runlevel(8) tool may be used by system administrators to obtain the
94 current runlevel, this reads the RUNLEVEL and PREVLEVEL variables from
95 its own environment or reads the current and previous runlevel from
96 /var/run/utmp.
97
98 The who(1) -r command may also be used to read the current runlevel
99 from /var/run/utmp.
100
101 This provides full compatibility with System V.
102
103 During the boot scripts, where the /var/run/utmp file may not yet be
104 writable, the RUNLEVEL and PREVLEVEL environment variables will be
105 available so telinit(8) will still provide the correct values.
106
107 Once the boot scripts have finished, while the environment variables
108 may no longer be available, the /var/run/utmp file will be and the most
109 recent telinit(8) invocation should have successfully written to it.
110
111 Boot time records
112 The telinit(8) tool also takes care of writing the boot time record to
113 both /var/run/utmp and /var/log/wtmp.
114
115 This is written if the previous runlevel in these files does not match
116 the previous runlevel obtained from its environment. In general this
117 occurs when switching from runlevel S to the default runlevel, at which
118 point the /var/run/utmp and /var/log/wtmp files are both writable, and
119 the telinit(8) invocation to do the switch has RUNLEVEL=S in its envi‐
120 ronment.
121
123 A service running in the typical multi-user runlevels might use:
124
125 start on runlevel [2345]
126 stop on runlevel [!2345]
127
129 runlevel(8) init(8) telinit(8) shutdown(8) who(1)
130
131
132
133Upstart 2009-07-09 runlevel(7)