K35vncserver K54dovecot K70bcm5820 K90isicom S13portmap
S55sshd S97messagebus K15httpd K20spamassassin K35winbind
K54pxe K74ntpd K91isdn S14nfslock S56rawdevices
S97rhnsd K15postgresql K24irda K40mars-nwe K55routed
K74ups K95firstboot S17keytable S56xinetd S99local
K16rarpd K25squid K45arpwatch K61hpoj K74ypserv
S00microcode_ctl S20random S84privoxy S99mdmonitor
These scripts are actually symbolic links to system service scripts under the /etc/rc.d/init.d
directory (yours might look different, depending on whether you are working with a workstation or server installation and the services or software packages installed on your system):
# ls /etc/rc.d/init.d/
acpid bgpd firstboot ip6tables keytable mars-nwe nfs
postgresql ripd smartd vncserver zebra aep1000 bluetooth
FreeWnn ipchains killall mdmonitor nfslock privoxy
ripngd smb vsftpd amd bootparamd functions iptables
kprop messagebus nscd psacct routed snmpd winbind
anacron canna gkrellmd irda krb524 microcode_ctl ntpd
pxe rstatd snmptrapd xfs apmd cpqarrayd gpm
irqbalance krb5kdc mysqld ospf6d radiusd rusersd
spamassassin xinetd arpwatch crond halt iscsi kudzu
named ospfd radvd rwalld squid ypbind
atalk cups hpoj isdn ldap netdump pand
random rwhod sshd yppasswdd atd dhcpd
httpd isicom lisa netdump-server pcmcia rarpd
saslauthd syslog ypserv autofs dhcrelay identd kadmin
lm_sensors netfs portmap rawdevices sendmail tux
ypxfrd bcm5820 dovecot innd kdcrotate mailman
network postfix rhnsd single ups yum
The rc5.d links are prefaced with a letter and number, such as K15 or S10. The ( K
) or ( S
) in these prefixes indicates whether a particular service should be killed ( K
) or started ( S
), and passes a value of stop or start to the appropriate /etc/rc.d/init.d script
. The number in the prefix executes the specific /etc/rc.d/init.d
script in a particular order. The symlinks have numbers to delineate the order in which they are started. Nothing is sacred about a specific number, but some services need to be running before others are started. You would not want your Fedora system to attempt, for example, to mount a remote Network File System (NFS) volume without first starting networking and NFS services.
After all the system services are started for your runlevel, init
starts the graphical login (because you are in runlevel 5). The graphical login's definition appears toward the end of /etc/inittab
and looks like this:
# Run xdm in runlevel 5 x:5:respawn:/etc/X11/prefdm -nodaemon
This example shows that the shell script named prefdm executes the proper X11 display manager when Fedora is booted to runlevel 5.
Booting to a Nondefault Runlevel with GRUB
After you select a default runlevel, that runlevel is selected every time you restart the system from a power-off state. There might come a time when you do not want to boot into that runlevel. You might want to enter the maintenance mode or start the system without an active X server and graphical login to modify or repair the X server or desktop manager. You have to follow several specific steps to boot to a nondefault runlevel if you use GRUB, the default boot loader for Fedora.
NOTE
If you have enabled a GRUB password, you must first press p
, type your password, and then press Enter before using this boot method.
The GRUB boot loader passes arguments, or commands, to the kernel at boot time. These arguments are used, among other things, to tell GRUB where the kernel is located and also to pass specific parameters to the kernel, such as how much memory is available or how special hardware should be configured.
To override the default runlevel, you can add an additional kernel argument to GRUB as follows:
1. At the graphical boot screen, press e
(for edit), scroll down to select the kernel, and press e
again.
2. Press the spacebar, type single
or 1(Fedora allows S
and s
as well), and press Enter.
3. Finally, press b
to boot, and you'll boot into runlevel 1 instead of the default runlevel listed in /etc/inittab
.
Fedora includes several command-line and graphical system administration utilities you can use to start, stop, reorder, or restart various services in different runlevels. These commands (discussed later in this chapter) work by renaming, removing, or creating symbolic links from /etc/rc.d/init.d
to /etc/rc.d/rc.*
as appropriate. Many administrators use these commands to change the symbolic links to the scripts under each /etc/rc.d/rc*
directory rather than do it by hand.
The locations of symbolic links can also be confusing. Red Hat (and now Fedora) has traditionally kept them in one place, and the Linux Standards Base ( LSB ) requires that they now be located elsewhere. Because other scripts reference these files and it would be difficult to change them all, Fedora places symbolic links in the places specified by the LSB.
As you might surmise, symbolic links are very powerful tools in the system administrator's toolbox.
Understanding init
Scripts and the Final Stage of Initialization
Each /etc/rc.d/init.d
script, or init
script, contains logic that determines what to do when receiving a start or stop value. The logic might be a simple switch statement for execution, as in this example:
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
reload)
reload
;;
status)
rhstatus
;;
condrestart)
[ -f /var/lock/subsys/smb ] && restart || :
;;
*)
echo $"Usage: $0 {start|stop|restart|status|condrestart}"
exit 1
esac
Although the scripts can be used to customize the way that the system runs from power- on, absent the replacement of the kernel, this script approach also means that the system does not have to be halted in total to start, stop, upgrade, or install new services.
Note that not all scripts use this approach, and that other messages might be passed to the service script, such as restart
, reload
, or status
. Also, not all scripts respond to the same set of messages (with the exception of start
and stop
, which they all have to accept by convention) because each service might require special commands.
TIP
You can write your own init
scripts, using the existing scripts as examples. Sample scripts can also be found in /usr/share/doc/initscripts/sysvinitfiles,
along with a brief tutorial written by Red Hat and a brief explanation of all the options available to use in init
scripts.
Читать дальше