LAMP下的脚步声::再谈Debian的启动脚本

LAMP下的脚步声 看憨狗撑着LAMP,一步一步 << yeah.net需要smtp认证更改mew的配置, | 首页 | 机子不在,无法更新,觉得空荡荡的,不是个滋味 >> 再谈Debian的启动脚本 Time:2004-02-29 再看看Debian的启动脚本: 1:先是/etc/inittab。 id:5:initdefault: 接着: si::sysinit:/etc/init.d/rcS //这是和其他dist不同的地方,到底/etc/init.d/rcS干什么呢? 我们先进去 看看再说 ================================================ #下面的步骤进入/etc/init.d/rcS看看,等/etc/init.d/rcS执行 #完了,还要返回到/etc/inittab # #首先,定义PATH、runlevel、prevlevel然后导出到环境中 # PATH=/sbin:/bin:/usr/sbin:/usr/bin runlevel=S prevlevel=N umask 022 export PATH runlevel prevlevel #然后,判断是不是第一次安装系统,如果是,则检查并且执行安装 #程序留下的脚本 #/sbin/unconfigured.sh if [ -x /sbin/unconfigured.sh ] then /sbin/unconfigured.sh fi . /etc/default/rcS export VERBOSE #捕捉INT、QUIT、TSTP信号, trap ":" INT QUIT TSTP #检查/etc/rcS.d/目录,看是否有以S开头并且紧跟两个字符(实际 #上一般是两个数字0-99)命名的 #非普通(! -f "$i")文件,如果有则根据文件的类型作出两个选择 # 1,是.sh结尾的脚本时执行 # 2,如果不是.sh结尾的脚本,则传递给start参数执行这个文件 for i in /etc/rcS.d/S??* do # Ignore dangling symlinks for now. [ ! -f "$i" ] && continue case "$i" in *.sh) # Source shell script for speed. ( trap - INT QUIT TSTP set start . $i ) ;; *) # No sh extension, so fork subprocess. $i start ;; esac done #这是为了兼容其他系统的/etc/rc.boot脚本 [ -d /etc/rc.boot ] && run-parts /etc/rc.boot #这也是用于第一次安装系统后需要执行的脚本,安装成功后,系统上 #一般没有这个脚本 if [ -x /sbin/setup.sh ] then /sbin/setup.sh fi #/etc/rc.S/rcS脚本执行结束.返回/inittab ========================================== 返回/inittab,继续: 这是单用户模式下系统的动作 ~~:S:wait:/sbin/sulogin 接下来,根据系统进入的运行级别,执行对应的初始化工作,比如一些启动或者关闭一些服务进程啊什么的: l0:0:wait:/etc/init.d/rc 0 l1:1:wait:/etc/init.d/rc 1 l2:2:wait:/etc/init.d/rc 2 l3:3:wait:/etc/init.d/rc 3 l4:4:wait:/etc/init.d/rc 4 l5:5:wait:/etc/init.d/rc 5 l6:6:wait:/etc/init.d/rc 6 其实都差不多,进入哪个级别,就以哪个级别作为参数调用/etc/init.d/rc 下面我们看看这个/etc/init.d/rc又有和玄机呢?下面我们又进入/etc/init.d/rc这个世外桃源来看看 ========================================= #定义一个startup()函数 startup() { case "$1" in *.sh) $debug sh "$@" ;; *) $debug "$@" ;; esac } #捕捉INT、QUIT、TSTP信号 trap ":" INT QUIT TSTP # Set onlcr to avoid staircase effect. #设置终端,将 CR 字符映射为 NL 字符,避免阶梯效应 stty onlcr 0>&1 # Now find out what the current and what the previous runlevel are. runlevel=$RUNLEVEL # Get first argument. Set new runlevel to this argument. [ "$1" != "" ] && runlevel=$1 if [ "$runlevel" = "" ] then echo "Usage: $0 <runlevel>" >&2 exit 1 fi previous=$PREVLEVEL [ "$previous" = "" ] && previous=N export runlevel previous # Is there an rc directory for this new runlevel? if [ -d /etc/rc$runlevel.d ] then # First, run the KILL scripts. if [ $previous != N ] then for i in /etc/rc$runlevel.d/K[0-9][0-9]* do # Check if the script is there. [ ! -f $i ] && continue # Stop the service. startup $i stop done fi # Now run the START scripts for this runlevel. for i in /etc/rc$runlevel.d/S* do [ ! -f $i ] && continue if [ $previous != N ] && [ $previous != S ] then # # Find start script in previous runlevel and # stop script in this runlevel. # suffix=${i#/etc/rc$runlevel.d/S[0-9][0-9]} stop=/etc/rc$runlevel.d/K[0-9][0-9]$suffix previous_start=/etc/rc$previous.d/S[0-9][0-9]$suffix # # If there is a start script in the previous level # and _no_ stop script in this level, we don't # have to re-start the service. # [ -f $previous_start ] && [ ! -f $stop ] && continue fi case "$runlevel" in 0|6) startup $i stop ;; *) startup $i start ;; esac done fi # eof /etc/init.d/rc HackGou 撰写于 2004-02-29 11:28 | 发布于 之下 | 编辑 | Trackback(1) 评论 添加评论 最新更新 暂停更新本Blog google个人版 我姓敬(Gou) MSN支持成都通? Google的起家家当 教育网开放google Blog到web2.0 写扩展也有瘾! HTML检测133个错误 Gmail又送蛋了 关注的话题

原始快照:web.archive.org