Debian Codegraph @

doc/config/runlevels.md

raw symbols SCIP
1 Runlevels
2 =========
3
4 Finit supports runlevels, but unlike other init systems runlevels are
5 declared per service/run/task/sysv command. When booting up a system
6 Finit pass through three phases:
7
8 1. Setting up the console, parsing any command line options, and other
9 housekeeping tasks like mounting all filesystems, and calling `fsck`
10 2. Starting all run/task/services in runlevel S, then waiting for all
11 services to have started, and all run/tasks to have completed
12 3. Go to runlevel 2, or whatever the user has set in the configuration
13
14 Available runlevels:
15
16 - ` S`: bootStrap
17 - ` 1`: Single user mode
18 - `2-5`: traditional multi-user mode
19 - ` 6`: reboot
20 - `7-9`: multi-user mode (extra)
21 - ` 0`: shutdown
22
23 Runlevel S (bootStrap), is for tasks supposed to run once at boot, and
24 services like `syslogd`, which need to start early and run throughout
25 the lifetime of your system.
26
27 Example:
28
29 task [S] /lib/console-setup/console-setup.sh
30 service [S12345] env:-/etc/default/rsyslog rsyslogd -n $RSYSLOGD_ARGS
31
32 When bootstrap has completed, Finit moves to runlevel 2. This can be
33 changed in `/etc/finit.conf` using the `runlevel N` directive, or by a
34 script running in runlevel S that calls, e.g., `initctl runlevel 9`.
35 The latter is useful if startup scripts detect problems outside of
36 Finit's control, e.g., critical services/devices missing or hardware
37 problems.
38
39 Each runlevel must be allowed to "complete". Meaning, all services in
40 runlevel S must have started and all run/tasks have been started and
41 collected (exited). Finit waits 120 seconds for all run/tasks in S to
42 complete before proceeding to 2.
43
44 Finit first stops everything that is not allowed to run in 2, and then
45 brings up networking. Networking is expected to be available in all
46 runlevels except: S, 1 (single user level), 6, and 0. Networking is
47 enabled either by the `network script` directive, or if you have an
48 `/etc/network/interfaces` file, Finit calls `ifup -a` -- at the very
49 least the loopback interface is brought up.
50
51 > [!NOTE]
52 > When moving from runlevel S to 2, all run/task/services that were
53 > constrained to runlevel S only are dropped from bookkeeping. So when
54 > reaching the prompt, `initctl` will not show these run/tasks. This is
55 > a safety mechanism to prevent bootstrap-only tasks from accidentally
56 > being run again. E.g., `console-setup.sh` above.
57
58 Runlevel Configuration
59 ----------------------
60
61 **Syntax:** `runlevel <N>`
62
63 The system runlevel to go to after bootstrap (S) has completed. `N` is
64 the runlevel number 0-9, where 6 is reserved for reboot and 0 for halt.
65 Completed in this context means all services have been started and all
66 run/tasks have been started and collected.
67
68 It is recommended to keep runlevel 1 as single-user mode, because
69 Finit disables networking in this mode.
70
71 *Default:* 2
72
73 > [!NOTE]
74 > Only read and executed in runlevel S (bootstrap).
75
76 Networking
77 ----------
78
79 **Syntax:** `network <PATH>`
80
81 Script or program to bring up networking, with optional arguments.
82
83 Deprecated. We recommend using dedicated task/run stanzas per runlevel,
84 or `/etc/network/interfaces` if you have a system with `ifupdown`, like
85 Debian, Ubuntu, Linux Mint, or an embedded BusyBox system.
86
87 > [!NOTE]
88 > Only read and executed in runlevel S (bootstrap).
89
90 System Hostname
91 ---------------
92
93 **Syntax:** `host <NAME>`, or `hostname <NAME>`
94
95 Set system hostname to NAME, unless `/etc/hostname` exists in which case
96 the contents of that file is used.
97
98 Deprecated. We recommend using `/etc/hostname` instead.
99
100 > [!NOTE]
101 > Only read and executed in runlevel S (bootstrap).
102
103 Kernel Modules
104 --------------
105
106 **Syntax:** `module <MODULE> [ARGS]`
107
108 Load a kernel module, with optional arguments. Similar to `insmod`
109 command line tool.
110
111 Deprecated, there is both a `modules-load.so` and a `modprobe.so` plugin
112 that can handle module loading better. The former supports loading from
113 `/etc/modules-load.d/`, the latter uses kernel modinfo to automatically
114 load (or coldplug) every required module. For hotplug we recommend the
115 BusyBox mdev tool, add to `/etc/mdev.conf`:
116
117 $MODALIAS=.* root:root 0660 @modprobe -b "$MODALIAS"
118
119 > [!NOTE]
120 > Only read and executed in runlevel S (bootstrap).
121
122 Resource Limits
123 ---------------
124
125 **Syntax:** `rlimit [hard|soft] RESOURCE <LIMIT|unlimited>`
126
127 Set the hard or soft limit for a resource, or both if that argument is
128 omitted. `RESOURCE` is the lower-case `RLIMIT_` string constants from
129 `setrlimit(2)`, without prefix. E.g. to set `RLIMIT_CPU`, use `cpu`.
130
131 LIMIT is an integer that depends on the resource being modified, see
132 the man page, or the kernel `/proc/PID/limits` file, for details.
133 Finit versions before v3.1 used `infinity` for `unlimited`, which is
134 still supported, albeit deprecated.
135
136 # No process is allowed more than 8MB of address space
137 rlimit hard as 8388608
138
139 # Core dumps may be arbitrarily large
140 rlimit soft core infinity
141
142 # CPU limit for all services, soft & hard = 10 sec
143 rlimit cpu 10
144
145 `rlimit` can be set globally, in `/etc/finit.conf`, or locally per
146 each `/etc/finit.d/*.conf` read. I.e., a set of task/run/service
147 stanzas can share the same rlimits if they are in the same .conf.
148
149 Miscellaneous Settings
150 ----------------------
151
152 **Syntax:** `reboot-delay <0-60>`
153
154 Optional delay at reboot (or shutdown or halt) to allow kernel
155 filesystem threads to complete after calling `sync(2)` before
156 rebooting. This applies primarily to filesystems that do not
157 have a reboot notifier implemented. At the point of writing,
158 the only known filesystems affected are: ubifs, jffs2.
159
160 *Default:* 0 (disabled)
161
162 When enabled (non-zero), this delay runs after file systems have been
163 unmounted and the root filesystem has been remounted read-only, and
164 sync(2) has been called, twice.
165
166 > "On Linux, sync is only guaranteed to schedule the dirty blocks for
167 > writing; it can actually take a short time before all the blocks are
168 > finally written.