From owner-cvs-all Thu Jun 24 1: 5:51 1999 Delivered-To: cvs-all@freebsd.org Received: from relay.ucb.crimea.ua (relay.ucb.crimea.ua [212.110.138.1]) by hub.freebsd.org (Postfix) with ESMTP id BB8E214D09; Thu, 24 Jun 1999 00:57:47 -0700 (PDT) (envelope-from ru@ucb.crimea.ua) Received: (from ru@localhost) by relay.ucb.crimea.ua (8.9.3/8.9.3/UCB) id KAA00791; Thu, 24 Jun 1999 10:36:14 +0300 (EEST) (envelope-from ru) Date: Thu, 24 Jun 1999 10:36:14 +0300 From: Ruslan Ermilov To: Greg Lehey Cc: Peter Wemm , 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> References: <199906231025.DAA28793@freefall.freebsd.org> <19990623140249.E07C275@overcee.netplex.com.au> <19990623172304.A90012@relay.ucb.crimea.ua> <19990624094842.E417@freebie.lemis.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=+xNpyl7Qekk2NvDX X-Mailer: Mutt 0.95.3i In-Reply-To: <19990624094842.E417@freebie.lemis.com>; from Greg Lehey on Thu, Jun 24, 1999 at 09:48:42AM +0930 X-Operating-System: FreeBSD 3.2-STABLE i386 Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk --+xNpyl7Qekk2NvDX Content-Type: text/plain; charset=us-ascii 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 --+xNpyl7Qekk2NvDX Content-Type: text/plain Content-Disposition: attachment; filename="init.txt" Content-Transfer-Encoding: quoted-printable init(M) ******* _________________________________________________________________________= ___ i=08in=08ni=08it=08t,=08, =08 t=08te=08el=08li=08in=08ni=08it=08t =08 -= =08--=08- =08 s=08si=08ig=08gn=08na=08al=08l =08 t=08th=08he=08e =08 i=08in= =08ni=08it=08t =08 p=08pr=08ro=08oc=08ce=08es=08ss=08s =08 Syntax =3D=3D=3D=3D=3D=3D /=08/e=08et=08tc=08c/=08/i=08in=08ni=08it=08t [ 0=0801=0812=0823=0834=084= 5=0856=086S=08Ss=08sQ=08Qq=08qa=08ab=08bc=08c ] /=08/b=08bi=08in=08n/=08/t=08te=08el=08li=08in=08ni=08it=08t [ 0=0801=081= 2=0823=0834=0845=0856=086S=08Ss=08sQ=08Qq=08qa=08ab=08bc=08c ] Description =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D t=08te=08el=08li=08in=08ni=08it=08t-=08- =08 s=08si=08ig=08gn=08na=08al= =08l =08 t=08th=08he=08e =08 i=08in=08ni=08it=08t =08 p=08pr=08ro=08oc=08ce= =08es=08ss=08s =08 The i=08in=08ni=08it=08t process (PID 1) is a general process spawner cre= ated at boot time. Its primary role is to create processes from information stored in the fi= le _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b (see _=08i_= =08n_=08i_=08t_=08t_=08a_=08b(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 i=08in=08ni= =08it=08t for each of these run-levels are defined in _=08/_=08e_=08t_=08c_=08/_=08i_=08n_= =08i_=08t_=08t_=08a_=08b. i=08in=08ni=08it=08t can be in one of the run-levels: 0=080 through 6=086 or S. (Run-levels S and s=08s are identic= al.) _=08r_=08o_=08o_=08t can use either i=08in=08ni=08it=08t or t=08te=08el= =08li=08in=08ni=08it=08t to change the operating system's run-level by signaling the original i=08in=08ni=08it=08t process (PID 1).= (Note that t=08te=08el=08li=08in=08ni=08it=08t is a link to i=08in=08ni=08it=08t.) If a 0=080 through 6=086 is entered, i=08in=08ni=08it=08t enters the corr= esponding run-level. Note that the run-levels 0=080, 1=081, 5=085, and 6=086 are reserved states fo= r shutting the system down; run-levels 2=082, 3=083, and 4=084 are available as normal o= perating states. If the file _=08/_=08e_=08t_=08c_=08/_=08d_=08e_=08f_=08a_=08u_=08l_=08t_= =08/_=08b_=08o_=08o_=08t (see _=08b_=08o_=08o_=08t(F)) contains the string = MAPKEY=3DYES, i=08in=08ni=08it=08t invokes m=08ma=08ap=08pk=08ke=08ey=08y(M) to map the= console keyboard. If the call to m=08ma=08ap=08pk=08ke=08ey=08y succeeds, the console is set to 8-bits no parity. If the call fails, and the string SERIAL8=3DYES appears in _=08/_=08e_=08t_=08c_=08/_=08d_=08e_= =08f_=08a_=08u_=08l_=08t_=08/_=08b_=08o_=08o_=08t, a serial console device is assumed and set to 8-bits no parity. For additional information on keywords, see b=08bo=08oo=08ot=08ts=08st=08tr=08ri=08in=08ng=08g(HW) a= nd b=08bo=08oo=08ot=08t(HW). i=08in=08ni=08it=08t and t=08te=08el=08li=08in=08ni=08it=08t accept one o= f the following arguments: 0=080 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. 1=081 Put the system in single-user mode. Unmount all file systems = except the _=08r_=08o_=08o_=08t filesystem. All user processes are kille= d except those connected to the console. This state can be executed only from the console. 2=082 Put the system in multiuser mode. All multiuser environment t= erminal processes and daemons are spawned. This state is commonly referred to as multiuser mode. 3=083, 4=084 Are available to be defined as alternative multiuser envi= ronment configurations. They are not necessary for system operation and a= re not normally used. 5=085 Stop the UNIX system and go to the firmware monitor. 6=086 Stop the UNIX system and reboot to the run-level defined by t= he initdefault entry in _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08= t_=08t_=08a_=08b. a=08a,b=08b,c=08c Process only those _=08/_=08e_=08t_=08c_=08/_=08i_=08= n_=08i_=08t_=08t_=08a_=08b entries having the a=08a, b=08b or c=08c run-level set. These are pseudo-states, which may be defined to r= un certain commands, but which do not cause the current run-level to change. Q=08Q,q=08q Re-examine _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_= =08t_=08a_=08b. s=08s =20 S=08S 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 _=08/_=08e_=08t_=08c_=08/_=08i_= =08n_=08i_=08t_=08t_=08a_=08b file. If this file does not exist, then by default the only legal run-level that i= =08in=08ni=08it=08t can enter is the single-user mode. When the system enters S=08S o= r s=08s, all mounted file systems remain mounted and only processes spawned by i=08in=08ni=08it=08t are killed. When a UNIX system is booted, i=08in=08ni=08it=08t is invoked and the fol= lowing actions occur: 1. i=08in=08ni=08it=08t looks in _=08/_=08e_=08t_=08c_=08/_=08d_=08e_=08f= _=08a_=08u_=08l_=08t_=08/_=08b_=08o_=08o_=08t to determine if autoboot on p= anic is desired. 2. i=08in=08ni=08it=08t looks to see if DEFAULT_LEVEL=3D_=08n is specifie= d in _=08/_=08e_=08t_=08c_=08/_=08d_=08e_=08f_=08a_=08u_=08l_=08t_=08/_=08b= _=08o_=08o_=08t. If it is, then _=08n is the default level, otherwise, the user is prom= pted 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 s=08su=08ul= =08lo=08og=08gi=08in=08n command, which requires the user to enter the _=08r_=08o_=08o_=08t pas= sword, 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), i=08in=08ni= =08it=08t will only reinitialize to single-user mode if the _=08/_=08e_=08t_=08c_=08/_=08i= _=08n_=08i_=08t_=08t_=08a_=08b file does not exist. On entering single-user mode for the first time since the system last booted, i=08in=08ni=08it=08t only runs entries in _=08/_=08e_=08t_=08c_= =08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b (see _=08i_=08n_=08i_=08t_=08t_=08a= _=08b(F)) which have sysinit set in their _=08a_=08c_=08t_=08i_=08o_=08n field. If i=08in=08ni=08it=08t enters a run-level other than single-user mode fo= r the first time since the system last boooted, it runs entries in _=08/_=08e_=08t_=08c_= =08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b which specify this run-level (or none) in their _=08r_=08s_=08t_=08a_=08t_=08e = field and which have boot and bootwait set in their _=08a_=08c_=08t_=08i_=08o_=08n field. In this w= ay, any special initialization of the operating system, such as mounting filesystems, can take place before users are allowed onto the system. i=08in=08ni=08it=08t= then scans _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b and executes= all other entries that are to be processed for the new run-level. In a multiuser environment, _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t= _=08t_=08a_=08b is set up so that i=08in=08ni=08it=08t will create a g=08ge=08et=08tt=08ty=08y process for each terminal that the administra= tor sets up to respawn. To spawn each process in _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_= =08t_=08a_=08b, i=08in=08ni=08it=08t reads each entry and for each entry that should be respawned, it forks a child process. i=08in=08ni=08i= t=08t spawns each process by forking a shell to run the job in. To set up the environment f= or this shell, i=08in=08ni=08it=08t uses the _=08/_=08e_=08t_=08c_=08/_=08i_= =08n_=08i_=08t_=08s_=08c_=08r_=08i_=08p_=08t file which contains the definitions of some global variables, for example, TZ, HZ, and PATH. (For more information about _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08s= _=08c_=08r_=08i_=08p_=08t, see i=08in=08ni=08it=08ts=08sc=08cr=08ri=08ip=08= pt=08t(ADM).) After i=08in=08ni=08it=08t has spawned all of the processes specified by = _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b, it waits for: o one of its descendant processes to die, o a powerfail signal, o a signal from another i=08in=08ni=08it=08t or t=08te=08el=08li=08in=08= ni=08it=08t 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 b=08bo=08oo=08ot=08t(HW) for further details. When one of these conditions occurs, i=08in=08ni=08it=08t re-examines _= =08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b. New entries can be added to _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08= t_=08a_=08b at any time; however, i=08in=08ni=08it=08t still waits for one of the above four conditions to occur before re-examining _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b. To get arou= nd this, an i=08in=08ni=08it=08t =08 Q=08Q or i=08in=08ni=08it=08t =08 q=08= q command wakes i=08in=08ni=08it=08t to re-examine _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b i= mmediately. When i=08in=08ni=08it=08t comes up at boot time and whenever the system c= hanges from single-user mode to another run-level, i=08in=08ni=08it=08t sets the i=08= io=08oc=08ct=08tl=08l(S) states of the virtual console to those modes saved in the file _=08/_=08e_=08t_=08c_=08= /_=08i_=08o_=08c_=08t_=08l_=08._=08s_=08y_=08s_=08c_=08o_=08n. This file is written by i=08in=08ni=08it=08t whenever single-user mode is ente= red. When a run-level change request is made, i=08in=08ni=08it=08t sends the w= arning signal (SIGTERM) to all processes that are undefined in the target run-level. i=08in=08ni=08it=08t waits 5 seconds before forcibly terminating these pr= ocesses 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 i=08in=08ni=08it=08t receives a signal tell= ing it that a process it spawned has died, it records the fact and the reason it died in _=08/_=08e_=08t_=08c_=08/_=08u_=08t_=08m_=08p and _=08/_=08e_=08t_=08c_= =08/_=08w_=08t_=08m_=08p if it exists (see w=08wh=08ho=08o(C)). A history o= f the processes spawned is kept in _=08/_=08e_=08t_=08c_=08/_=08w_=08t_=08m_=08= p. If i=08in=08ni=08it=08t receives a power failure signal (SIGPWR), it scan= s _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b for special entries of the type powerfail or powerwait. These entries are invoked (if the run-level permits this) before any further processing tak= es place. In this way i=08in=08ni=08it=08t can perform various cleanup and r= ecording functions during the powerdown of the operating system. Diagnostics =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D If i=08in=08ni=08it=08t finds that it is respawning an entry from _=08/_= =08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b 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 i=08in=08ni=08it=08t = (t=08te=08el=08li=08in=08ni=08it=08t). This prevents i=08in=08ni=08it=08t from eating up system resources when someon= e makes a typographical error in the _=08i_=08n_=08i_=08t_=08t_=08a_=08b file or a = program is removed that is referenced in _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08= b. When attempting to boot the system, failure of i=08in=08ni=08it=08t to pr= ompt for a new run-level may be because the virtual system console is linked to a device other than the physical system console. Limitations =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Only _=08r_=08o_=08o_=08t can run i=08in=08ni=08it=08t and t=08te=08el=08= li=08in=08ni=08it=08t. The S=08S or s=08s state must not be used indiscriminately in the _=08/_= =08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b 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 t= he ``normal'' system console (_=08t_=08t_=08y_=080_=081), then the prompt fo= r going multiuser will be displayed on the the tty from which i=08in=08ni=08it=08t =08 S=08S was= last invoked, which could be any tty on the system. The system console device (_=08/_=08d_=08e_=08v= _=08/_=08s_=08y_=08s_=08c_=08o_=08n) remains linked to the tty from which the last i=08in=08ni=08it=08t =08 S=08S is i= nvoked. Rebooting the system does n=08no=08ot=08t reset this to _=08t_=08t_=08y_=080_=081. If the _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08s_=08c_=08r_=08i_= =08p_=08t file is not present, i=08in=08ni=08it=08t will print a warning on= the console and spawn the job without setting up the global environment. The change to _=08/_=08e_=08t_=08c_=08/_=08g_=08e_=08t_=08t_=08y_=08d_=08= e_=08f_=08s, as described in the ``Limitations'' section of the _=08g_=08e_=08t_=08t_=08y_=08d_=08e_=08f_=08s(F) manual page, will pe= rmit 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 g=08ge=08et=08tt=08= ty=08y 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: s=08st=08tt=08ty=08y =08 -=08-i=08is=08st=08tr=08ri=08ip=08p =08 c=08cs= =08s8=088 The _=08/_=08e_=08t_=08c_=08/_=08T_=08I_=08M_=08E_=08Z_=08O_=08N_=08E fil= e should exist. /=08/e=08et=08tc=08c/=08/i=08in=08ni=08it=08ts=08sc=08cr=08= ri=08ip=08pt=08t tries to execute this file to set the correct TZ variable for the system. Files =3D=3D=3D=3D=3D _=08/_=08e_=08t_=08c_=08/_=08d_=08e_=08f_=08a_=08u_=08l_=08t_=08/_=08b_= =08o_=08o_=08t _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08t_=08a_=08b _=08/_=08e_=08t_=08c_=08/_=08u_=08t_=08m_=08p _=08/_=08e_=08t_=08c_=08/_=08w_=08t_=08m_=08p _=08/_=08e_=08t_=08c_=08/_=08i_=08o_=08c_=08t_=08l_=08._=08s_=08y_=08s_= =08c_=08o_=08n _=08/_=08e_=08t_=08c_=08/_=08i_=08n_=08i_=08t_=08s_=08c_=08r_=08i_=08p_= =08t _=08/_=08d_=08e_=08v_=08/_=08c_=08o_=08n_=08s_=08o_=08l_=08e _=08/_=08d_=08e_=08v_=08/_=08c_=08o_=08n_=08t_=08t_=08y See also =3D=3D=3D=3D=3D=3D=3D=3D b=08bo=08oo=08ot=08t(F), b=08bo=08oo=08ot=08t(HW), d=08di=08is=08sa=08ab= =08bl=08le=08e(C), e=08en=08na=08ab=08bl=08le=08e(C), g=08ge=08et=08tt=08ty= =08y(M), g=08ge=08et=08tt=08ty=08yd=08de=08ef=08fs=08s(F), i=08in=08ni=08it= =08tc=08co=08on=08nd=08d (ADM), i=08in=08ni=08it=08ts=08sc=08cr=08ri=08ip=08pt=08t(ADM), i=08in=08= ni=08it=08tt=08ta=08ab=08b(F), k=08ki=08il=08ll=08l(S), l=08lo=08og=08gi=08= in=08n(M), s=08sh=08h(C), s=08sh=08hu=08ut=08td=08do=08ow=08wn=08n(ADM), s=08st=08tt=08ty=08y(C), s=08su=08ul=08lo=08og=08gi=08in=08n(ADM), t=08te= =08er=08rm=08mi=08io=08o(M), u=08ut=08tm=08mp=08p(F), w=08wh=08ho=08o(C) Standards conformance =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D i=08in=08ni=08it=08t is conformant with: AT&T SVID Issue 2. t=08te=08el=08li=08in=08ni=08it=08t is not part of any currently supporte= d standard. _=081_=08 _=08M_=08a_=08y_=08 _=081_=089_=089_=085 --+xNpyl7Qekk2NvDX-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message