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