Merge branch 'vendor/EXPAT'
[dragonfly.git] / sbin / init / init.8
1 .\" Copyright (c) 1980, 1991, 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Donn Seeley at Berkeley Software Design, Inc.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)init.8      8.3 (Berkeley) 4/18/94
36 .\" $FreeBSD: src/sbin/init/init.8,v 1.22.2.11 2003/05/03 22:19:20 keramida Exp $
37 .\"
38 .Dd November 14, 2012
39 .Dt INIT 8
40 .Os
41 .Sh NAME
42 .Nm init
43 .Nd process control initialization
44 .Sh SYNOPSIS
45 .Nm
46 .Nm
47 .Oo
48 .Cm 0 | 1 | 6 |
49 .Cm c | q
50 .Oc
51 .Sh DESCRIPTION
52 The
53 .Nm
54 utility
55 is the last stage of the boot process.
56 It normally runs the automatic reboot sequence as described in
57 .Xr rc 8 ,
58 and if this succeeds, begins multi-user operation.
59 If the reboot scripts fail,
60 .Nm
61 commences single-user operation by giving
62 the super-user a shell on the console.
63 The
64 .Nm
65 utility may be passed parameters
66 from the boot program to
67 prevent the system from going multi-user and to instead execute
68 a single-user shell without starting the normal daemons.
69 The system is then quiescent for maintenance work and may
70 later be made to go to multi-user by exiting the
71 single-user shell (with ^D).
72 This
73 causes
74 .Nm
75 to run the
76 .Pa /etc/rc
77 start up command file in fastboot mode (skipping disk checks).
78 .Pp
79 If the
80 .Em console
81 entry in the
82 .Xr ttys 5
83 file is marked
84 .Dq insecure ,
85 then
86 .Nm
87 will require that the super-user password be
88 entered before the system will start a single-user shell.
89 The password check is skipped if the
90 .Em console
91 is marked as
92 .Dq secure .
93 .Pp
94 The kernel runs with five different levels of security.
95 Any super-user process can raise the security level, but no process
96 can lower it.
97 The security levels are:
98 .Bl -tag -width flag
99 .It Ic -1
100 Permanently insecure mode \- always run the system in level 0 mode.
101 This is the default initial value.
102 .It Ic 0
103 Insecure mode \- immutable and append-only flags may be turned off.
104 All devices may be read or written subject to their permissions.
105 .It Ic 1
106 Secure mode \- the system immutable and system append-only flags may not
107 be turned off;
108 disks for mounted file systems,
109 .Pa /dev/mem ,
110 and
111 .Pa /dev/kmem
112 may not be opened for writing;
113 kernel modules (see
114 .Xr kld 4 )
115 may not be loaded or unloaded.
116 .It Ic 2
117 Highly secure mode \- same as secure mode, plus disks may not be
118 opened for writing (except by
119 .Xr mount 2 )
120 whether mounted or not.
121 This level precludes tampering with file systems by unmounting them,
122 but also inhibits running
123 .Xr newfs 8
124 while the system is multi-user.
125 .Pp
126 In addition, kernel time changes are restricted to less than or equal to one
127 second.  Attempts to change the time by more than this will log the message
128 .Dq Time adjustment clamped to +1 second .
129 .It Ic 3
130 Network secure mode \- same as highly secure mode, plus
131 IP packet filter rules (see
132 .Xr ipfw 8
133 and
134 .Xr ipfirewall 4 )
135 cannot be changed and
136 .Xr dummynet 4
137 configuration cannot be adjusted.
138 .El
139 .Pp
140 If the security level is initially nonzero, then
141 .Nm
142 leaves it unchanged.
143 Otherwise,
144 .Nm
145 raises the level to 1 before going multi-user for the first time.
146 Since the level cannot be reduced, it will be at least 1 for
147 subsequent operation, even on return to single-user.
148 If a level higher than 1 is desired while running multi-user,
149 it can be set before going multi-user, e.g., by the startup script
150 .Xr rc 8 ,
151 using
152 .Xr sysctl 8
153 to set the
154 .Va kern.securelevel
155 variable to the required security level.
156 .Pp
157 In multi-user operation,
158 .Nm
159 maintains
160 processes for the terminal ports found in the file
161 .Xr ttys 5 .
162 The
163 .Nm
164 utility reads this file and executes the command found in the second field,
165 unless the first field refers to a device in
166 .Pa /dev
167 which is not configured.
168 The first field is supplied as the final argument to the command.
169 This command is usually
170 .Xr getty 8 ;
171 .Nm getty
172 opens and initializes the tty line
173 and
174 executes the
175 .Xr login 1
176 program.
177 The
178 .Nm login
179 program, when a valid user logs in,
180 executes a shell for that user.  When this shell
181 dies, either because the user logged out
182 or an abnormal termination occurred (a signal),
183 the
184 .Nm
185 utility wakes up, deletes the user
186 from the
187 .Xr utmp 5
188 file of current users and records the logout in the
189 .Xr wtmp 5
190 file.
191 The cycle is
192 then restarted by
193 .Nm
194 executing a new
195 .Nm getty
196 for the line.
197 .Pp
198 The
199 .Nm
200 utility can also be used to keep arbitrary daemons running,
201 automatically restarting them if they die.
202 In this case, the first field in the
203 .Xr ttys 5
204 file must not reference the path to a configured device node
205 and will be passed to the daemon
206 as the final argument on its command line.
207 This is similar to the facility offered in the
208 .At V
209 .Pa /etc/inittab .
210 .Pp
211 Line status (on, off, secure, getty, or window information)
212 may be changed in the
213 .Xr ttys 5
214 file without a reboot by sending the signal
215 .Dv SIGHUP
216 to
217 .Nm
218 with the command
219 .Dq Li "kill -HUP 1" .
220 On receipt of this signal,
221 .Nm
222 re-reads the
223 .Xr ttys 5
224 file.
225 When a line is turned off in
226 .Xr ttys 5 ,
227 .Nm
228 will send a
229 .Dv SIGHUP
230 signal to the controlling process for the session associated with the line.
231 For any lines that were previously turned off in the
232 .Xr ttys 5
233 file and are now on,
234 .Nm
235 executes the command specified in the second field.
236 If the command or window field for a line is changed,
237 the change takes effect at the end of the current
238 login session (e.g., the next time
239 .Nm
240 starts a process on the line).
241 If a line is commented out or deleted from
242 .Xr ttys 5 ,
243 .Nm
244 will not do anything at all to that line.
245 However, it will complain that the relationship between lines
246 in the
247 .Xr ttys 5
248 file and records in the
249 .Xr utmp 5
250 file is out of sync,
251 so this practice is not recommended.
252 .Pp
253 The
254 .Nm
255 utility will terminate multi-user operations and resume single-user mode
256 if sent a terminate
257 .Pq Dv TERM
258 signal, for example,
259 .Dq Li "kill \-TERM 1" .
260 If there are processes outstanding that are deadlocked (because of
261 hardware or software failure),
262 .Nm
263 will not wait for them all to die (which might take forever), but
264 will time out after 30 seconds and print a warning message.
265 .Pp
266 The
267 .Nm
268 utility will cease creating new processes
269 and allow the system to slowly die away, if it is sent a terminal stop
270 .Pq Dv TSTP
271 signal, i.e.\&
272 .Dq Li "kill \-TSTP 1" .
273 A later hangup will resume full
274 multi-user operations, or a terminate will start a single-user shell.
275 This hook is used by
276 .Xr reboot 8
277 and
278 .Xr halt 8 .
279 .Pp
280 The
281 .Nm
282 utility will terminate all possible processes (again, it will not wait
283 for deadlocked processes) and reboot the machine if sent the interrupt
284 .Pq Dv INT
285 signal, i.e.\&
286 .Dq Li "kill \-INT 1".
287 This is useful for shutting the machine down cleanly from inside the kernel
288 or from X when the machine appears to be hung.
289 .Pp
290 The
291 .Nm
292 utility will do the same, except it will halt the machine if sent
293 the user defined signal 1
294 .Pq Dv USR1 ,
295 or will halt and turn the power off (if hardware permits) if sent
296 the user defined signal 2
297 .Pq Dv USR2 .
298 .Pp
299 When shutting down the machine,
300 .Nm
301 will try to run the
302 .Pa /etc/rc.shutdown
303 script.
304 This script can be used to cleanly terminate specific programs such
305 as
306 .Nm innd
307 (the InterNetNews server).
308 If this script does not terminate within 120 seconds,
309 .Nm
310 will terminate it. The timeout can be configured via the
311 .Xr sysctl 8
312 variable
313 .Va kern.init_shutdown_timeout .
314 .Pp
315 The role of
316 .Nm
317 is so critical that if it dies, the system will reboot itself
318 automatically.
319 If, at bootstrap time, the
320 .Nm
321 process cannot be located, the system will panic with the message
322 .Dq "panic: init died (signal %d, exit %d)" .
323 .Pp
324 If run as a user process as shown in the second synopsis line,
325 .Nm
326 will emulate
327 .At V
328 behavior, i.e. super-user can specify the desired
329 .Em run-level
330 on a command line, and
331 .Nm
332 will signal the original
333 (PID 1)
334 .Nm
335 as follows:
336 .Bl -column Run-level SIGTERM
337 .It Sy "Run-level       Signal  Action"
338 .It Cm 0 Ta Dv SIGUSR2 Ta "Halt and turn the power off"
339 .It Cm 1 Ta Dv SIGTERM Ta "Go to single-user mode"
340 .It Cm 6 Ta Dv SIGINT Ta "Reboot the machine"
341 .It Cm c Ta Dv SIGTSTP Ta "Block further logins"
342 .It Cm q Ta Dv SIGHUP Ta Rescan the
343 .Xr ttys 5
344 file
345 .El
346 .Sh FILES
347 .Bl -tag -width /etc/rc.shutdown -compact
348 .It Pa /dev/console
349 system console device
350 .It Pa /dev/tty*
351 terminal ports found in
352 .Xr ttys 5
353 .It Pa /var/run/utmp
354 record of current users on the system
355 .It Pa /var/log/wtmp
356 record of all logins and logouts
357 .It Pa /etc/ttys
358 the terminal initialization information file
359 .It Pa /etc/rc
360 system startup commands
361 .It Pa /etc/rc.shutdown
362 system shutdown commands
363 .El
364 .Sh DIAGNOSTICS
365 .Bl -diag
366 .It "getty repeating too quickly on port %s, sleeping."
367 A process being started to service a line is exiting quickly
368 each time it is started.
369 This is often caused by a ringing or noisy terminal line.
370 .Bf -emphasis
371 Init will sleep for 30 seconds,
372 then continue trying to start the process.
373 .Ef
374 .It "some processes would not die; ps axl advised."
375 A process
376 is hung and could not be killed when the system was shutting down.
377 This condition is usually caused by a process
378 that is stuck in a device driver because of
379 a persistent device error condition.
380 .El
381 .Sh SEE ALSO
382 .Xr kill 1 ,
383 .Xr login 1 ,
384 .Xr sh 1 ,
385 .Xr dummynet 4 ,
386 .Xr ipfirewall 4 ,
387 .Xr kld 4 ,
388 .Xr ttys 5 ,
389 .Xr crash 8 ,
390 .Xr getty 8 ,
391 .Xr halt 8 ,
392 .Xr ipfw 8 ,
393 .Xr rc 8 ,
394 .Xr reboot 8 ,
395 .Xr shutdown 8 ,
396 .Xr sysctl 8
397 .Sh HISTORY
398 An
399 .Nm
400 utility appeared in
401 .At v6 .
402 .Sh CAVEATS
403 Systems without
404 .Xr sysctl 8
405 behave as though they have security level \-1.
406 .Pp
407 Setting the security level above 1 too early in the boot sequence can
408 prevent
409 .Xr fsck 8
410 from repairing inconsistent file systems.  The
411 preferred location to set the security level is at the end of
412 .Pa /etc/rc
413 after all multi-user startup actions are complete.