Date: Thu, 24 Jun 1999 10:36:14 +0300 From: Ruslan Ermilov <ru@FreeBSD.org> To: Greg Lehey <grog@lemis.com> Cc: Peter Wemm <peter@netplex.com.au>, cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org, billf@FreeBSD.org, des@FreeBSD.org Subject: Re: System V init syntax (was: cvs commit: src/sbin/init Makefile init.8 init.c src/sbin/reboot reboot.8 src/sbin/shutdown shutdown.8 shutdown.c) Message-ID: <19990624103614.E84404@relay.ucb.crimea.ua> In-Reply-To: <19990624094842.E417@freebie.lemis.com>; from Greg Lehey on Thu, Jun 24, 1999 at 09:48:42AM %2B0930 References: <199906231025.DAA28793@freefall.freebsd.org> <19990623140249.E07C275@overcee.netplex.com.au> <19990623172304.A90012@relay.ucb.crimea.ua> <19990624094842.E417@freebie.lemis.com>
next in thread | previous in thread | raw e-mail | index | archive | help
[-- Attachment #1 --] On Thu, Jun 24, 1999 at 09:48:42AM +0930, Greg Lehey wrote: > > Do we have clear-cut definitions of the run levels? If so, it's not > System V compatible :-) But that would be a prerequisite. > I do (see attached), and I tried to make our init as compatible as I can. Cheers, -- Ruslan Ermilov Sysadmin and DBA of the ru@ucb.crimea.ua United Commercial Bank, ru@FreeBSD.org FreeBSD committer, +380.652.247.647 Simferopol, Ukraine http://www.FreeBSD.org The Power To Serve http://www.oracle.com Enabling The Information Age [-- Attachment #2 --] init(M) ******* ____________________________________________________________________________ iinniitt,, tteelliinniitt ---- ssiiggnnaall tthhee iinniitt pprroocceessss Syntax ====== //eettcc//iinniitt [ 00112233445566SSssQQqqaabbcc ] //bbiinn//tteelliinniitt [ 00112233445566SSssQQqqaabbcc ] Description =========== tteelliinniitt-- ssiiggnnaall tthhee iinniitt pprroocceessss The iinniitt process (PID 1) is a general process spawner created at boot time. Its primary role is to create processes from information stored in the file _/_e_t_c_/_i_n_i_t_t_a_b (see _i_n_i_t_t_a_b(F) for further details). At any given time, the system is in one of eight possible run-levels. A run-level is a software configuration of the system under which only a selected group of processes exist. The processes spawned by iinniitt for each of these run-levels are defined in _/_e_t_c_/_i_n_i_t_t_a_b. iinniitt can be in one of the run-levels: 00 through 66 or S. (Run-levels S and ss are identical.) _r_o_o_t can use either iinniitt or tteelliinniitt to change the operating system's run-level by signaling the original iinniitt process (PID 1). (Note that tteelliinniitt is a link to iinniitt.) If a 00 through 66 is entered, iinniitt enters the corresponding run-level. Note that the run-levels 00, 11, 55, and 66 are reserved states for shutting the system down; run-levels 22, 33, and 44 are available as normal operating states. If the file _/_e_t_c_/_d_e_f_a_u_l_t_/_b_o_o_t (see _b_o_o_t(F)) contains the string MAPKEY=YES, iinniitt invokes mmaappkkeeyy(M) to map the console keyboard. If the call to mmaappkkeeyy succeeds, the console is set to 8-bits no parity. If the call fails, and the string SERIAL8=YES appears in _/_e_t_c_/_d_e_f_a_u_l_t_/_b_o_o_t, a serial console device is assumed and set to 8-bits no parity. For additional information on keywords, see bboooottssttrriinngg(HW) and bboooott(HW). iinniitt and tteelliinniitt accept one of the following arguments: 00 Shut the machine down so it is safe to remove the power. Have the machine remove power if it can. This state can be executed only from the console. 11 Put the system in single-user mode. Unmount all file systems except the _r_o_o_t filesystem. All user processes are killed except those connected to the console. This state can be executed only from the console. 22 Put the system in multiuser mode. All multiuser environment terminal processes and daemons are spawned. This state is commonly referred to as multiuser mode. 33, 44 Are available to be defined as alternative multiuser environment configurations. They are not necessary for system operation and are not normally used. 55 Stop the UNIX system and go to the firmware monitor. 66 Stop the UNIX system and reboot to the run-level defined by the initdefault entry in _/_e_t_c_/_i_n_i_t_t_a_b. aa,bb,cc Process only those _/_e_t_c_/_i_n_i_t_t_a_b entries having the aa, bb or cc run-level set. These are pseudo-states, which may be defined to run certain commands, but which do not cause the current run-level to change. QQ,qq Re-examine _/_e_t_c_/_i_n_i_t_t_a_b. ss SS Enter single-user mode. When this occurs, the terminal which executed this command becomes the system console (see ``Limitations'' for more information about console device assignment). This is the only run-level that doesn't require the existence of a properly formatted _/_e_t_c_/_i_n_i_t_t_a_b file. If this file does not exist, then by default the only legal run-level that iinniitt can enter is the single-user mode. When the system enters SS or ss, all mounted file systems remain mounted and only processes spawned by iinniitt are killed. When a UNIX system is booted, iinniitt is invoked and the following actions occur: 1. iinniitt looks in _/_e_t_c_/_d_e_f_a_u_l_t_/_b_o_o_t to determine if autoboot on panic is desired. 2. iinniitt looks to see if DEFAULT_LEVEL=_n is specified in _/_e_t_c_/_d_e_f_a_u_l_t_/_b_o_o_t. If it is, then _n is the default level, otherwise, the user is prompted to see if they wish to go to multiuser or system maintenance mode (single-user mode). 3. In single-user mode, the virtual console terminal is assigned to the user's terminal and is opened for reading and writing. The ssuullooggiinn command, which requires the user to enter the _r_o_o_t password, is invoked and a message is generated on the physical console saying where the virtual console has been relocated. Note that if the shell is terminated (via an end-of-file), iinniitt will only reinitialize to single-user mode if the _/_e_t_c_/_i_n_i_t_t_a_b file does not exist. On entering single-user mode for the first time since the system last booted, iinniitt only runs entries in _/_e_t_c_/_i_n_i_t_t_a_b (see _i_n_i_t_t_a_b(F)) which have sysinit set in their _a_c_t_i_o_n field. If iinniitt enters a run-level other than single-user mode for the first time since the system last boooted, it runs entries in _/_e_t_c_/_i_n_i_t_t_a_b which specify this run-level (or none) in their _r_s_t_a_t_e field and which have boot and bootwait set in their _a_c_t_i_o_n field. In this way, any special initialization of the operating system, such as mounting filesystems, can take place before users are allowed onto the system. iinniitt then scans _/_e_t_c_/_i_n_i_t_t_a_b and executes all other entries that are to be processed for the new run-level. In a multiuser environment, _/_e_t_c_/_i_n_i_t_t_a_b is set up so that iinniitt will create a ggeettttyy process for each terminal that the administrator sets up to respawn. To spawn each process in _/_e_t_c_/_i_n_i_t_t_a_b, iinniitt reads each entry and for each entry that should be respawned, it forks a child process. iinniitt spawns each process by forking a shell to run the job in. To set up the environment for this shell, iinniitt uses the _/_e_t_c_/_i_n_i_t_s_c_r_i_p_t file which contains the definitions of some global variables, for example, TZ, HZ, and PATH. (For more information about _/_e_t_c_/_i_n_i_t_s_c_r_i_p_t, see iinniittssccrriipptt(ADM).) After iinniitt has spawned all of the processes specified by _/_e_t_c_/_i_n_i_t_t_a_b, it waits for: o one of its descendant processes to die, o a powerfail signal, o a signal from another iinniitt or tteelliinniitt process to change the system's run-level, or possibility of SLEEPTIME wait, o SLEEPTIME seconds to elapse (unless this has been set to the default of zero). See bboooott(HW) for further details. When one of these conditions occurs, iinniitt re-examines _/_e_t_c_/_i_n_i_t_t_a_b. New entries can be added to _/_e_t_c_/_i_n_i_t_t_a_b at any time; however, iinniitt still waits for one of the above four conditions to occur before re-examining _/_e_t_c_/_i_n_i_t_t_a_b. To get around this, an iinniitt QQ or iinniitt qq command wakes iinniitt to re-examine _/_e_t_c_/_i_n_i_t_t_a_b immediately. When iinniitt comes up at boot time and whenever the system changes from single-user mode to another run-level, iinniitt sets the iiooccttll(S) states of the virtual console to those modes saved in the file _/_e_t_c_/_i_o_c_t_l_._s_y_s_c_o_n. This file is written by iinniitt whenever single-user mode is entered. When a run-level change request is made, iinniitt sends the warning signal (SIGTERM) to all processes that are undefined in the target run-level. iinniitt waits 5 seconds before forcibly terminating these processes via the kill signal (SIGKILL). The shell running on each terminal will terminate when the user types an end-of-file or hangs up. When iinniitt receives a signal telling it that a process it spawned has died, it records the fact and the reason it died in _/_e_t_c_/_u_t_m_p and _/_e_t_c_/_w_t_m_p if it exists (see wwhhoo(C)). A history of the processes spawned is kept in _/_e_t_c_/_w_t_m_p. If iinniitt receives a power failure signal (SIGPWR), it scans _/_e_t_c_/_i_n_i_t_t_a_b for special entries of the type powerfail or powerwait. These entries are invoked (if the run-level permits this) before any further processing takes place. In this way iinniitt can perform various cleanup and recording functions during the powerdown of the operating system. Diagnostics =========== If iinniitt finds that it is respawning an entry from _/_e_t_c_/_i_n_i_t_t_a_b more than 10 times in 2 minutes, it will assume that there is an error in the command string in the entry, and generate an error message on the system console. It will then refuse to respawn this entry until either 5 minutes has elapsed or it receives a signal from a user-spawned iinniitt (tteelliinniitt). This prevents iinniitt from eating up system resources when someone makes a typographical error in the _i_n_i_t_t_a_b file or a program is removed that is referenced in _/_e_t_c_/_i_n_i_t_t_a_b. When attempting to boot the system, failure of iinniitt to prompt for a new run-level may be because the virtual system console is linked to a device other than the physical system console. Limitations =========== Only _r_o_o_t can run iinniitt and tteelliinniitt. The SS or ss state must not be used indiscriminately in the _/_e_t_c_/_i_n_i_t_t_a_b file. A good rule to follow when modifying this file is to avoid adding this state to any line other than the initdefault. The assignment of the console device may seem confusing at first. Whenever the system is rebooted, the first boot up messages will be displayed on the ``normal'' system console (_t_t_y_0_1), then the prompt for going multiuser will be displayed on the the tty from which iinniitt SS was last invoked, which could be any tty on the system. The system console device (_/_d_e_v_/_s_y_s_c_o_n) remains linked to the tty from which the last iinniitt SS is invoked. Rebooting the system does nnoott reset this to _t_t_y_0_1. If the _/_e_t_c_/_i_n_i_t_s_c_r_i_p_t file is not present, iinniitt will print a warning on the console and spawn the job without setting up the global environment. The change to _/_e_t_c_/_g_e_t_t_y_d_e_f_s, as described in the ``Limitations'' section of the _g_e_t_t_y_d_e_f_s(F) manual page, will permit terminals to pass 8 bits to the system as long as the system is in multiuser state (run-level greater than 1). When the system changes to single-user state, the ggeettttyy is killed and the terminal attributes are lost. To permit a terminal to pass 8 bits to the system in single-user state, after you are in single-user state, type: ssttttyy --iissttrriipp ccss88 The _/_e_t_c_/_T_I_M_E_Z_O_N_E file should exist. //eettcc//iinniittssccrriipptt tries to execute this file to set the correct TZ variable for the system. Files ===== _/_e_t_c_/_d_e_f_a_u_l_t_/_b_o_o_t _/_e_t_c_/_i_n_i_t_t_a_b _/_e_t_c_/_u_t_m_p _/_e_t_c_/_w_t_m_p _/_e_t_c_/_i_o_c_t_l_._s_y_s_c_o_n _/_e_t_c_/_i_n_i_t_s_c_r_i_p_t _/_d_e_v_/_c_o_n_s_o_l_e _/_d_e_v_/_c_o_n_t_t_y See also ======== bboooott(F), bboooott(HW), ddiissaabbllee(C), eennaabbllee(C), ggeettttyy(M), ggeettttyyddeeffss(F), iinniittccoonndd (ADM), iinniittssccrriipptt(ADM), iinniittttaabb(F), kkiillll(S), llooggiinn(M), sshh(C), sshhuuttddoowwnn(ADM), ssttttyy(C), ssuullooggiinn(ADM), tteerrmmiioo(M), uuttmmpp(F), wwhhoo(C) Standards conformance ===================== iinniitt is conformant with: AT&T SVID Issue 2. tteelliinniitt is not part of any currently supported standard. _1_ _M_a_y_ _1_9_9_5
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990624103614.E84404>
