Scroll to navigation

INIT(8) Manual de Administrador de Sistema Linux INIT(8)

NOME

init, telinit - inicialização do controle de processos

RESUMO

/sbin/init [ -a ] [ -s ] [ -b ] [ -z xxx ] [ 0123456Ss ]
/sbin/init [ --version ]
/sbin/telinit [ -t SEGUNDOS ] [ 0123456sSQqabcUu ]
/sbin/telinit [ -e VAR[=VAL] ]

DESCRIÇÃO

Init

init É o pai de todos os processos. O seu papel principal é criar processos a partir de um script guardado no ficheiro /etc/inittab (veja inittab(5)). Este ficheiro geralmente tem entradas que fazem o init gerar gettys em cada linha que os utilizadores podem registar. Também controla processos autónomos requeridos por qualquer sistema particular.

RUNLEVELS (NÍVEIS DE EXECUÇÃO)

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.

Os runlevels S, 0, 1, e 6 são reservados. O runlevel S é usado para inicializar o sistema no arranque. Quando se arranca o runlevel S (no arranque) ou runlevel 1 (comutar de um runlevel de multi-utilizador) o sistema entra em "modo de único-utilizador", após o qual o runlevel actual é S. O runlevel 0 é usado para parar o sistema; o runlevel 6 é usado para reiniciar o sistema.

Após arrancar através de S o sistema entra automaticamente em um dos runlevels de multi-utilizador 2 a 5, a menos que existam problemas que precisem de ser corrigidos pelo administrador em modo de único-utilizador. Normalmente após entrar em modo de único-utilizador o administrador executa manutenção e depois reinicia o sistema.

Para mais informação, veja os manuais de shutdown(8) e inittab(5).

Runlevels 7–9 are also valid, though not really documented. This is because "traditional" Unix variants don't use them.

Os runlevels S e s são o mesmo. Internamente são nomes alternativos para o mesmo runlevel.

ARRANCAR

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.

O runlevel S ou s inicializa o sistema e não requer um ficheiro /etc/inittab.

Em modo de único utilizador, /sbin/sulogin é invocado em /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.

Quando entra em modo multi-utilizador pela primeira vez, o init executa as entradas boot e bootwait para permitir que os sistemas de ficheiros sejam montados antes dos utilizadores fazerem login. Depois todas as entradas que correspondem ao runlevel são processadas.

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.

De cada vez que um filho termina, o init regista o facto e a razão de este ter terminado em /var/run/utmp e /var/log/wtmp, desde que estes ficheiros existam.

MODIFICAR OS RUNLEVELS

Após ter gerado todos os processos especificados, o init espera que um dos seus processos descendentes termine, por um sinal de falha de energia, ou até ser sinalizado pelo telinit para mudar o runlevel do sistema. Quando uma das três condições de cima ocorre, ele re-examina o ficheiro /etc/inittab. Novas entradas podem ser adicionadas a este ficheiro a qualquer altura. No entanto, o init ainda espera que uma das três condições de cima ocorra. Para fornecer uma resposta imediata, o comando telinit Q ou q pode acordar o init para re-examinar (recarregar) o ficheiro /etc/inittab.

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:

Power is failing, UPS is providing the power. Execute the powerwait and powerfail entries.
A energia foi restaurada, executa as entradas powerokwait.
The power is failing and the UPS has a low battery. Execute the powerfailnow entries.

Se /etc/powerstatus não existir ou conter nada mais do que as letras F, O ou L, o init irá comportar-se como se tivesse lido a letra 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.

Quando o init é requerido para mudar o runlevel, eles envia o sinal de aviso SIGTERM a todos os processos que não estão definidos no novo runlevel. Depois espera 3 segundos antes de terminar à força estes processos via sinal SIGKILL. Note que o init assume que todos estes processos (e os seus descendentes) permanecem no mesmo grupo de processos no qual o init originalmente criou para eles. Se qualquer processo modificou a sua afiliação de grupo de processo não irá receber estes sinais. Tais processos precisam de ser terminados em separado.

TELINIT

/sbin/telinit está vinculado a /sbin/init. Recebe um argumento de um caractere e faz sinal ao init para executar a acção apropriada. Os seguintes argumentos servem como directivas para o telinit:

0, 1, 2, 3, 4, 5 ou 6
diz ao init para comutar para o nível de execução especificado.
diz ao init para processar apenas aquelas entradas no ficheiro /etc/inittab que têm runlevel a,b ou c.
diz ao init para re-examinar o ficheiro /etc/inittab.
diz ao init para comutar para modo de único utilizador.
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.

O telinit pode dizer ao init quanto tempo deve esperar entre enviar aos processos os sinais SIGTERM e SIGKILL. A predefinição é 3 segundos, mas isto pode ser mudado com a opção -t.

O telinit -e diz ao init para mudar o ambiente para os processos que ele gera. O argumento de -e ou está no formato de VAR=VAL o qual define a variável VAR para o valor VAL, ou no formato VAR (sem o sinal de igual) o qual remove a definição da variável VAR.

O telinit só pode ser invocado por utilizadores com privilégios apropriados.

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.

AMBIENTE

O Init define as seguintes variáveis de ambiente para todos os seus filhos:

/bin:/usr/bin:/sbin:/usr/sbin
As the name says. Useful to determine if a script runs directly from init.
O actual nível de execução do sistema.
O runlevel anterior (útil após uma mudança de runlevel).
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.

BOOTFLAGS

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:

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
O runlevel para o qual arrancar.
Arranca directamente para shell de único utilizador sem correr quaisquer scripts de arranque.
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.
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.
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.

INTERFACE

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.

SINAIS

O Init reage a vários sinais:

Tem o mesmo efeito que telinit q.
On receipt of this signals, init closes and re-opens its control fifo, /run/initctl. Useful for bootscripts when /dev is remounted.
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.
Normally the kernel sends this signal to init when CTRL-ALT-DEL is pressed. It activates the ctrlaltdel action.
O kernel envia este sinal quando a tecla KeyboardSignal é pressionada. Activa a acção kbrequest.

CONFORMIDADE COM

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.

FICHEIROS

/etc/inittab
/etc/initscript
/dev/console
/var/run/utmp
/var/log/wtmp
/run/initctl

AVISOS

O init assume que os processos e os descendentes dos processos permanecem no mesmo grupo de processos que foi originalmente criado para eles. Se os processos mudarem o seu grupo, o init não consegue mata-los e você pode acabar com dois processos a ler a partir de uma linha de terminal.

Num sistema Debian, entrar no runlevel 1 faz com que todos os processos sejam mortos excepto para tópicos de kernel e o script que faz a matança e outros processos na sua sessão. Como consequência disto, não é seguro retornar de runlevel 1 para um runlevel de multi-utilizador: os daemons que foram arrancados no runlevel S e são precisos para o funcionamento normal não estão mais a correr. O sistema deve ser reiniciado.

DIAGNÓSTICO

Se o init descobrir que está continuamente a renascer uma entrada mais de 10 vezes em 2 minutos,irá assumir que existe um erro na string de comando, gerar uma mensagem de erro na consola do sistema, e recusar o renascer desta entrada até que ou tenham passado 5 minutos ou tenha recebido um sinal. Isto previne de comer os recursos do sistema quando alguém comete um erro tipográfico no ficheiro /etc/inittab ou o programa para a entrada foi removido.

AUTOR

Miquel van Smoorenburg, initial manual page by Michael Haardt.

VEJA TAMBÉM

getty(1), login(1), sh(1), runlevel(8), shutdown(8), kill(1), initctl(5), inittab(5), initscript(5), utmp(5)

29 Julho 2004 sysvinit