- bookworm 3.06-4
- bookworm-backports 3.08-3~bpo12+2
- testing 3.14-1
- unstable 3.14-1
- experimental 3.14-2
INIT(8) | Podręcznik administratora systemu Linux | INIT(8) |
NAZWA¶
init, telinit - sterowanie procesu inicjującego
SKŁADNIA¶
/sbin/init [ -a ] [ -s ] [ -b ] [
-z xxx] [ 0123456Ss ]
/sbin/init [ --version ]
/sbin/telinit [ -t SEKUNDY ] [ 0123456sSQqabcUu ]
/sbin/telinit [ -e
ZMIENNA[=WARTOŚĆ] ]
OPIS¶
Init¶
Init jest przodkiem wszystkich procesów. Jego głównym zadaniem jest stworzenie procesów w oparciu o skrypt zapisany w pliku /etc/inittab (patrz też inittab(5)). Ten plik zawiera zwykle pozycje, które każą procesowi init pomnażać getty na każdej linii, na które użytkownicy mogą się zalogować. Kontroluje też samodzielne procesy, których istnienie jest konieczne w danym systemie.
POZIOMY PRACY¶
A runlevel is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init for each of these runlevels are defined in the /etc/inittab file. init can be in one of eight runlevels: 0–6 and S (a.k.a., s). The runlevel is changed by having a privileged user run telinit, which sends appropriate signals to init, telling it which runlevel to change to.
Tryby pracy S, 0, 1, oraz 6 są zarezerwowane. Tryb S jest używany do zainicjowania systemu, podczas jego rozruchu. Gdy uruchamiany jest tryb pracy S (w czasie rozruchu) lub tryb pracy 1 (przełączanie się z trybu wielu użytkowników), system jest wprowadzany w tryb pracy jednego użytkownika ("single-user mode"), po którym bieżącym poziomem pracy jest S. Tryb 0 jest używany, by zatrzymać system; tryb 6, by przeładować system (reboot).
Po zakończeniu rozruchu w poziomie S, system jest automatycznie wprowadzany w jeden z trybów wielu użytkowników, od 2 do 5, chyba że wystąpił problem, który musi zostać naprawiony przez administratora, w trybie jednego użytkownika. Po przejściu w tryb jednego użytkownika administrator zwykle zajmuje się konserwacją, a następnie przeładowuje system.
Aby uzyskać więcej informacji na ten temat, proszę zapoznać się ze stronami podręcznika shutdown(8) i inittab(5).
Runlevels 7–9 are also valid, though not really documented. This is because "traditional" Unix variants don't use them.
Poziomy S i s są w rzeczywistości takie same. Wewnętrznie są to tylko zastępcze nazwy dla tego samego trybu pracy.
ROZRUCH¶
After init is invoked as the last step of the kernel boot sequence, it looks for the file /etc/inittab to see if there is an entry of the type initdefault (see inittab(5)). The initdefault entry determines the initial runlevel of the system. If there is no such entry (or no /etc/inittab at all), a runlevel must be entered at the system console.
Poziom S lub s wprowadza system w tryb jednego użytkownika i nie wymaga pliku /etc/inittab.
W trybie jednego użytkownika, wywoływany jest /sbin/sulogin na urządzeniu /dev/console.
When entering single user mode, init initializes the consoles stty settings to sane values. Clocal mode is set. Hardware speed and handshaking are not changed.
Podczas wchodzenia w tryb wielu użytkowników po raz pierwszy, init wykonuje pozycje boot i bootwait, by pozwolić systemom plików zamontować się zanim użytkownicy będą mogli się zalogować. Potem wykonywane są wszystkie pozycje przypisane danemu poziomowi pracy.
When starting a new process, init first checks whether the file /etc/initscript exists. If it does, it uses this script to start the process.
Za każdym razem, gdy proces potomny się zakończy, init zapamiętuje ten fakt i powód śmierci procesu jest zapisany w /var/run/utmp i /var/log/wtmp, pod warunkiem, że te pliki istnieją.
ZMIENIANIE TRYBÓW PRACY¶
After it has spawned all of the processes specified, init waits for one of its descendant processes to die, a powerfail signal, or until it is signaled by telinit to change the system's runlevel. When one of the above three conditions occurs, it re-examines the /etc/inittab file. New entries can be added to this file at any time. However, init still waits for one of the above three conditions to occur. To provide for an instantaneous response, the telinit Q or q command can wake up init to re-examine (reload) the /etc/inittab file.
If init is not in single user mode and receives a powerfail signal (SIGPWR), it reads the file /etc/powerstatus. It then starts a command based on the contents of this file:
- F(AIL)
- Power is failing, UPS is providing the power. Execute the powerwait and powerfail entries.
- O(K)
- Zasilanie powróciło, uruchamia wpisy powerokwait.
- L(OW)
- The power is failing and the UPS has a low battery. Execute the powerfailnow entries.
Jeżeli plik /etc/powerstatus nie istnieje lub zawiera cokolwiek innego niż jedną z liter F, O lub L, init zachowa się tak, jakby przeczytał F.
Usage of SIGPWR and /etc/powerstatus is discouraged. Someone wanting to interact with init should use the /run/initctl control channel – see the initctl(5) manual page for more documentation about this.
Gdy init jest proszony o zmianę poziomu działania, wysyła sygnał ostrzegawczy SIGTERM do wszystkich procesów, które nie są zdefiniowane w nowym poziomie pracy. Potem czeka 5 sekund zanim "na siłę" zakończy te procesy poprzez sygnał SIGKILL. Zauważ, że init zakłada, że wszystkie te procesy (i ich potomki) pozostają w tej samej grupie procesów, którą init oryginalnie im utworzył. Jeżeli jakikolwiek proces zmienił swą przynależność do grupy procesów to nie odbierze tych sygnałów. Tego typu procesy muszą być kończone osobno (np. demony wszelakie - przyp. tłum.).
TELINIT¶
/sbin/telinit jest symbolicznym dowiązaniem do /sbin/init. Pobiera on jednoznakowy argument i sygnały init, by podjął stosowne działanie. Poniższe argumenty można stosować jako rozkazy dla telinit:
- 0, 1, 2, 3, 4, 5 lub 6
- mówią procesowi init by przełączył w odpowiedni poziom działania.
- a, b, c
- tell init to process only those /etc/inittab file entries having runlevel a, b or c.
- Q lub q
- każą procesowi init jeszcze raz przeczytać plik /etc/inittab.
- S lub s
- mówią żeby init przełączył w tryb jednego użytkownika.
- U lub u
- tell init to re-execute itself (preserving the state). No re-examining of /etc/inittab file happens. Runlevel should be one of Ss0123456 otherwise request would be silently ignored.
telinit może także powiedzieć procesowi init, jak długo powinien on czekać między wysyłaniem sygnałów SIGTERM i SIGKILL. Domyślną wartością jest 3 sekund, ale może być ona zmieniona za pomocą opcji -t.
telinit -e mówi procesowi init, aby zmienił środowisko procesów, które mnoży. Argumenty do -e mogą mieć postać ZMIENNA=WARTOŚĆ, która ustawia zmiennej ZMIENNA wartość WARTOŚĆ lub postać ZMIENNA (bez znaku równości), która usuwa zmienną ZMIENNA.
telinit może być wywoływany tylko przez użytkowników uprzywilejowanych.
The init binary checks if it is init or telinit by looking at its process id; the real init's process id is always 1. From this it follows that instead of calling telinit one can also just use init instead as a shortcut.
ŚRODOWISKO¶
Init ustawia następujące zmienne środowiskowe dla wszystkich swoich dzieci:
- PATH
- /bin:/usr/bin:/sbin:/usr/sbin
- INIT_VERSION
- As the name says. Useful to determine if a script runs directly from init.
- RUNLEVEL
- Obecny poziom pracy systemu.
- PREVLEVEL
- Poprzedni poziom pracy systemu (użyteczne po zmianie poziomów).
- CONSOLE
- The system console. This is really inherited from the kernel; however if it is not set init will set it to /dev/console by default.
FLAGI STARTOWE¶
It is possible to pass a number of flags to init from the boot monitor (e.g., LILO or GRUB). init accepts the following flags:
- -s, S, single
- Single user mode boot. In this mode /etc/inittab is examined and the bootup rc scripts are usually run before the single user mode shell is started.
- 1–5
- Poziom działania w jakim system ma wystartować.
- -b, emergency
- Wejście bezpośrednio w tryb jednego użytkownika bez uruchamiania żadnych innych skryptów startowych.
- -a, auto
- The LILO boot loader adds the word "auto" to the command line if it booted the kernel with the default command line (without user intervention). If this is found init sets the "AUTOBOOT" environment variable to "yes". Note that you cannot use this for any security measures – of course the user could specify "auto" or -a on the command line manually.
- -z xxx
- The argument to -z is ignored. You can use this to expand the command line a bit, so that it takes some more space on the stack. init can then manipulate the command line so that ps(1) shows the current runlevel.
- --version
- This argument, when used on its own, displays the current version of init to the console/stdout. It is a quick way to determine which init software and version is being used. After the version information is displayed, init immediately exits with a return code of zero.
INTERFEJS¶
init listens on a fifo as, /run/initctl, for messages. Telinit uses this to communicate with init. The interface is not very well documented or finished. Those interested should study the initreq.h file in the src/ subdirectory of the init source code tar archive.
SYGNAŁY¶
Init reaguje na następujące sygnały:
- SIGHUP
- Ma ten sam efekt co telinit q.
- SIGUSR1
- On receipt of this signals, init closes and re-opens its control fifo, /run/initctl. Useful for bootscripts when /dev is remounted.
- SIGUSR2
- When init receives SIGUSR2, init closes and leaves the control fifo, /run/initctl, closed. This may be used to make sure init is not holding open any files. However, it also prevents init from switching runlevels. Which means commands like shutdown no longer work. The fifo can be re-opened by sending init the SIGUSR1 signal.
- SIGINT
- Normally the kernel sends this signal to init when CTRL-ALT-DEL is pressed. It activates the ctrlaltdel action.
- SIGWINCH
- Jądro wysyła ten sygnał jeśli wciśnięty został klawisz KeyboardSignal. Aktywuje to akcję kbrequest.
ZGODNE Z¶
init is compatible with the System V init. It works closely together with the scripts in the directories /etc/init.d and /etc/rc{runlevel}.d. If your system uses this convention, there should be a README file in the directory /etc/init.d explaining how these scripts work.
PLIKI¶
/etc/inittab /etc/initscript /dev/console /var/run/utmp /var/log/wtmp /run/initctl
OSTRZEŻENIA¶
init zakłada, że procesy i ich procesy potomne pozostają w tej samej grupie procesów, która była dla nich oryginalnie stworzona. Jeżeli jakikolwiek proces zmienił swą przynależność do grupy procesów, init nie może ich zabić i może skończyć się na tym, że zostaną dwa procesy czytające z jednego wiersza terminala.
W systemie Debian, wejście w poziom pracy 1 powoduje zabicie wszystkich procesów z wyjątkiem wątków jądra i skryptu który wykonuje zabijanie oraz innych procesów w jego sesji. W konsekwencji, powracanie z poziomu 1 do poziomu pracy trybu wielu użytkowników nie jest bezpieczne: demony, które zostały uruchomione w poziomie S i są wymagane do normalnego działania nie są dłużej uruchomione. System powinien zostać uruchomiony ponownie.
DIAGNOSTYKA¶
Jeśli init zorientuje się, że wciąż powtarza namnażanie zadanego procesu częściej niż 10 razy w ciągu 2 minut, wtedy założy, że gdzieś w wywołaniu komendy jest błąd, wyśle wiadomość o błędzie na konsolę systemu, i przerwie pomnażanie danego pola do upłynięcia 5 minut lub do odebrania sygnału. Zapobiega to "zjadaniu" zasobów systemu gdy ktoś popełni literówkę w pliku /etc/inittab lub gdy program normalnie uruchamiany dla danego wpisu jest usunięty.
AUTOR¶
Miquel van Smoorenburg , pierwszą wersję strony podręcznika napisał Michael Haardt.
ZOBACZ TAKŻE¶
getty(1), login(1), sh(1), runlevel(8), shutdown(8), kill(1), initctl(5), inittab(5), initscript(5), utmp(5)
29 lipca 2004 | sysvinit |