/etc/rc?.d目录和/etc/rc?文件 发信人: cloudsky (晓舟·轩辕明月), 信区: Linux 标 题: /etc/rc?.d目录和/etc/rc?文件简介 发信站: 武汉白云黄鹤站 (Thu Feb 4 22:31:41 1999) , 转信
标题:/etc/rc?.d目录和/etc/rc?文件分析
运行级0-6分别对应着一个/etc/rc?.d目录和一个/etc/rc?文件。rc?文件是个shell script,从/etc/inittab文件分析中可以看到,当进入运行级?时,rc?文件就会得到执行。从上面的示例文件中看到缺省实际运行级是3,注意到rc2也被执行了,下面是rc2示例
#!/sbin/sh PATH=/usr/sbin:/usr/bin set `/usr/bin/who -r` if [ x$9 = "xS" -o x$9 = "x1" ] then echo 'The system is coming up. Please wait.' BOOT=yes elif [ x$7 = "x2" ] then echo 'Changing to state 2.' if [ -d /etc/rc2.d ] then for f in /etc/rc2.d/K* { if [ -s ${f} ] then case ${f} in *.sh) . ${f} ;; *) /sbin/sh ${f} stop ;; esac fi } fi fi if [ x$9 != "x2" -a x$9 != "x3" -a -d /etc/rc2.d ] then for f in /etc/rc2.d/S* { if [ -s ${f} ] then case ${f} in *.sh) . ${f} ;; # source it *) /sbin/sh ${f} start ;; # sub shell esac fi } fi #if [ ! -s /etc/rc2.d/.ports.sem ] #then # /sbin/ports # echo "ports completed" > /etc/rc2.d/.ports.sem #fi # Start historical section. if [ "${BOOT}" = "yes" -a -d /etc/rc.d ] then for f in `/usr/bin/ls /etc/rc.d` { if [ ! -s /etc/init.d/${f} ] then /sbin/sh /etc/rc.d/${f} fi } fi # End historical section. if [ "${BOOT}" = "yes" -a x$7 = "x2" ] then echo 'The system is ready.' elif [ x$7 = "x2" ] then echo 'Change to state 2 has been completed.' fi
可以看到,rc2的主要任务是启动或终止/etc/rc2.d目录下的相关文件,这些文件也是shell script文件。这些文件具有如下格式:S??name或者K??nameK表示当进入运行级2时需执行此文件以终止某些进程,S表示当进入运行级2时需执行此文件以启动某些进程。??是00-99的数字,代表了终止和启动的顺序。name对应一个文件名,通常是/etc/init.d/name,注意这实际是些硬链接。
|