Search     or:     and:
 LINUX 
 Language 
 Kernel 
 Package 
 Book 
 Test 
 OS 
 Forum 
 iakovlev.org 
 Kernels
 Boot 
 Memory 
 File system
 0.01
 1.0 
 2.0 
 2.4 
 2.6 
 3.x 
 4.x 
 5.x 
 6.x 
 Интервью 
 Kernel
 HOW-TO 1
 Ptrace
 Kernel-Rebuild-HOWTO
=> Runlevel
 Linux daemons
 FAQ
NEWS
Последние статьи :
  Тренажёр 16.01   
  Эльбрус 05.12   
  Алгоритмы 12.04   
  Rust 07.11   
  Go 25.12   
  EXT4 10.11   
  FS benchmark 15.09   
  Сетунь 23.07   
  Trees 25.06   
  Apache 03.02   
 
TOP 20
 MINIX...3057 
 Solaris...2933 
 LD...2905 
 Linux Kernel 2.6...2470 
 William Gropp...2182 
 Rodriguez 6...2015 
 C++ Templates 3...1945 
 Trees...1938 
 Kamran Husain...1866 
 Secure Programming for Li...1792 
 Максвелл 5...1710 
 DevFS...1694 
 Part 3...1684 
 Stein-MacEachern-> Час...1632 
 Go Web ...1627 
 Ethreal 4...1619 
 Стивенс 9...1607 
 Arrays...1607 
 Максвелл 1...1593 
 FAQ...1539 
 
  01.01.2024 : 3621733 посещений 

iakovlev.org

run-level

Posted by tsstahl in the Debian section on Fri 12 Aug 2005 at 14:26

'runlevel' определяет , какие программы выполняются во время system startup.

Linux run levels - это числа от 0 до 6. Почему остановились на 6 ? На то есть исторические причины.

В следующей таблице приведен список run levels:

 
  * 0		System Halt
  * 1		Single user
  * 2		Full multi-user mode (Default)
  * 3-5		Same as 2
  * 6		System Reboot
 

Исключая начальный этап загрузки , система может переходить из одного runlevel к другому .

Special Run Levels

Ну , 0 - это понятно , останов системы. X86-процессоры поновее просто вырубают питание при достижении run level = 0 . X86-процессоры постарее будут выводить мессагу .

Run Level 1 - 'single user' режим. Его можно перевести как 'отладочный' . В этом режиме нет запущенных демонов .

(В этот режим можно попасть с помощью boot loader, lilo или grub ).

Уровни со 2 по 5 - это многопользовательские режимы , которые являются режимом по умолчанию в стандартных дистрибутивах . 3-й уровень изпользуется для консоли и 5-й для иксов.

6-й используется для reboot.

Есть еще один уровень - 'S' , который система использует по своему усмотрению.

Where Does a Run Level Live?

Как и все в Linux , run levels прописаны в файловой системе. Их можно найти в /etc каталоге :

/etc/rc0.d		Run level 0
 /etc/rc1.d		Run level 1
 /etc/rc2.d		Run level 2
 /etc/rc3.d		Run level 3
 /etc/rc4.d		Run level 4
 /etc/rc5.d		Run level 5
 /etc/rc6.d		Run level 6
 

Содержимое rcX.d каталога определяет, что происходит для данного run level.

(S)tart files, (K)ill files

Давайте глянем на run level 2 .

Содержимое rc2.d каталога:

S10sysklogd  S20cupsys   S20mailman  S20usermin  S91apache         S99xdm
 S11klogd     S20exim4    S20makedev  S20xfs      S91apache2
 S14ppp       S20fam      S20pcmcia   S20xprint   S99gdm
 S18portmap   S20hylafax  S20samba    S89atd      S99rmnologin
 S20acpid     S20inetd    S20ssh      S89cron     S99stop-bootlogd
 

Каждый файл - это символическая ссылка на скрипт в каталоге /etc/init.d , которая контролирует определенный демон.

(Смотрите как можно добавить свой скрипт)

Эти символические ссылки имеют формат :

[K | S] + nn + [string] 
 

[string] - это имя исполняемого прилинкованного файла . 'nn' цифры 01-99;чем меньше номер , тем раньше запускается программа. K - Kill, S - Start.

Когда система приходит в следующий runlevel, будут выполняться скрипты , начинающиеся с S . То же самое верно и для K . 'S' вызывают программу со 'start'-параметром, 'K' - со 'stop' параметром. Если демон уже запущен , он не будет снова запускаться .

Пример :

S20exim4 -> ../init.d/exim4
 S20fam -> ../init.d/fam
 S20hylafax -> ../init.d/hylafax
 S20inetd -> ../init.d/inetd
 S20mailman -> ../init.d/mailman
 S20makedev -> ../init.d/makedev
 S20pcmcia -> ../init.d/pcmcia
 S20samba -> ../init.d/samba
 S20ssh -> ../init.d/ssh
 

Как мы видим , программы запускаются в алфавитном порядке.

Transitioning Between Run levels

Когда вы покидаете runlevel, ничего не происходит. Все случается , когда вы приходите в новый run level.

Каталог rcX.d :

rc2.d:

K01xdm      S18portmap S20fam     S20makedev S20usermin S89cron    S99rmnologin
 S10sysklogd S20acpid   S20hylafax S20pcmcia  S20xfs     S91apache  S99stop-bootlogd
 S11klogd    S20cupsys  S20inetd   S20samba   S20xprint  S91apache2 S99xdm
 S14ppp      S20exim4   S20mailman S20ssh     S89atd     S99gdm
 

rc3.d:

K01gdm       S20acpid    S20inetd    S20ssh      S89cron           S99xdm
 S10sysklogd  S20cupsys   S20mailman  S20usermin  S91apache
 S11klogd     S20exim4    S20makedev  S20xfs      S91apache2
 S14ppp       S20fam      S20pcmcia   S20xprint   S99rmnologin
 S18portmap   S20hylafax  S20samba    S89atd      S99stop-bootlogd
 

Взгляните внимательно на эти 2 каталога .

Сначала в конце 2-го run level мы запускаем S99gdm - графический дисплей-менеджер , а при входе в 3-й run-level мы его тут же прибиваем , ибо 3-й run level - это уровень консоли по умолчанию.

That's great, but how do I change run levels?

Для определения текущего нужно запустить команду 'runlevel' :

ulsoho:/home/user1# runlevel
 N 2
 

Команда для изменения levels - 'telinit'.

telinit 3
 

telinit в качестве аргумента может иметь : 0,1,2,3,4,5,6,'S'. 'S' - это то же самое , что и 1 , но лучше не делайте так.

A note of caution is warranted here. You can easily use the telinit command to reboot (run level 6), or shutdown (run level 0) the system, but it is not recommended. Certain programs need special processing for an orderly shutdown. Bypassing the expected shutdown sequence can have dire effects on your data. Older _Unix_ systems are especially sensitive to shutdown/bootup operations

The preferred method for a serious runlevel change is 'shutdown'. There are easier mnemonics, but in a running system they all point to the 'shutdown' command. You can use the 'halt', or 'poweroff' command to stop a system and the 'reboot' command to restart your system. In each case they call the 'shutdown' command with different parameters.

(We've covered shutting down your Debian machine previously)

In a single system (non-networked, or no locally shared resources) environment, the shutdown choice is pretty much yours. However, in a multi-user production system the rule of thumb is learn the shutdown command. The two most basic uses of the 'shutdown' command are for halting, or rebooting. The important parameter to know for shutdown is WHEN is the action going to occur. Here is the command synopsis from the shutdown man page:

/sbin/shutdown [-t sec] [-arkhncfFHP] time [warning-message]
 

The vast majority of your shutdowns will follow one of these two forms:

shutdown -h now
 

or to reboot instead of halt:

shutdown -r now
 

Intuitively, the arguments mean 'halt' and 'reboot', respectively.

In a multi-user system like a file server, the most important parameter is 'time'. The time can be an actual clock time in the form of HH:MM, or a Julian style shutdown X minutes from now, denoted by the +X syntax. Note that the '+' is needed. The keyword 'now' is synonymous with '+0'. Here are two examples using the time parameter:

shutdown -h 16:30
 shutdown -r +10
 

Another important point to remember: once the shutdown command is issued, a notice is sent to all the users of the system and no further logins are allowed. For example, if you need to bring the system down at midnight, don't issue the shutdown command at noon and leave to take a nap. No new users will be able to login for the next 12 hours.

A good admin never takes a system down without warning the user community, but the shutdown notice is only sent after the command is executed! Fortunately, there are two ways around the downtime notification dilemma. The first is the 'motd', Message Of The Day. The motd is a useful feature that is often overlooked. Using the motd is easy and you are urged to read the simple man page for details. The second method of notification is the -k option. Using -k will send the downtime notice to all the users, but will not actually start the shutdown sequence. There is an important limitation to the shutdown notification: the downtime message is only sent 15 minutes (or less) prior to the actual shutdown.

The warning-message parameter may be useful for...high maintenance users. I find that the default message is authoritative and simple enough to accomplish the task.

Troubleshooting in Run Levels

Here is a tip contributed by Nicholas Petreley. Sometimes you may not want all the programs in a run level to execute. In this situation an easy way to disable a program is to rename it with the initial S, or K in lowercase. The system will ignore all programs that do not begin with a capital S, or K.

Оставьте свой комментарий !

Ваше имя:
Комментарий:
Оба поля являются обязательными

 Автор  Комментарий к данной статье