Linux 启动脚本 完全注释2 --- rc脚本注释

从/etc/inittab中可以看出,启动的核心就是rc脚本.
首先init程序调用rc脚本,并将级别传递给rc脚本.
其次rc脚本去调用该级别内(/etc/rcX.d)各项服务的脚本.

rc脚本的注释如下:
# ! / bin / sh
########################################################################
#  Begin  $ rc_base / init . d / rc
#
#  Description : Main  Run  Level Control Script
#
#  Authors     : Gerard Beekmans  - gerard@linuxfromscratch . org
#
#  Version     :  00.00
#
#  Notes       :
#
########################################################################

.   / etc / sysconfig / rc         # 指定rc_bash =/ etc / rc . d rc_functions  =   $ {rc_bash} / init . d / functions network_devices =/ etc / sysconfig / network-devices
.   $ {rc_functions}

#  This sets a few default terminal options .
stty sane

#  These  3  signals will  not  cause our script to  exit
trap 
""  INT QUIT TSTP     # trap是bash内建的命令,用来指定信号的行为,“”为忽略该信号

" ${1} "  ! =   ""  ] && runlevel =$ { 1 }         # 从参数中得到运行级别,在 / etc / inittab中指定的

if  [  " ${runlevel} "   =   ""  ] ;   then              # 运行级别为空则退出
    
echo   " Usage: ${0} <runlevel> "   > & 2
    
exit   1
fi

previous
=$ {PREVLEVEL}                     # 前一个级别
" ${previous} "   =   ""  ] && previous = N     # 没有前一级别则为n

if  [ ! -d  $ {rc_base} / rc $ {runlevel} . d ] ;   then      # 是否有该级别的目录
    boot_mesg 
" ${rc_base}/rc${runlevel}.d does not exist. "   $ {WARNING}
    boot_mesg_flush
    
exit   1
fi

#  Attempt to stop all service started by previous runlevel ,
#  and killed in this runlevel
# 结束该级别中K开头的脚本
if  [  " ${previous} "  ! =   " N "  ] ;   then          # 如果有前一个级别
    
for  i in  $( ls -v  $ {rc_base} / rc $ {runlevel} . d / K*  2 >   / dev / null )
    
do
        check_script_status

        suffix
=$ {i #$ rc_base / rc $ runlevel . d / K[ 0 - 9 ][ 0 - 9 ]}         # 脚本的名称,除去路径和K**
        prev_start
=$ rc_base / rc $ previous . d / S[ 0 - 9 ][ 0 - 9 ] $ suffix     # 前一级别
        sysinit_start
=$ rc_base / rcsysinit . d / S[ 0 - 9 ][ 0 - 9 ] $ suffix     # 系统初始化

        
if  [  " ${runlevel} "  ! =   " 0 "  ] && [  " ${runlevel} "  ! =   " 6 "  ] ;   then          # 不是重启和关机
            
if  [ ! -f  $ {prev_start} ] && [ ! -f  $ {sysinit_start} ] ;   then      # 如果不存在
                boot_mesg -n 
" WARNING: ${i} can't be "   $ {WARNING}             # 前一级别并没有启动该脚本
                boot_mesg -n 
"  executed because it was not "
                boot_mesg -n 
"  not started in the previous "
                boot_mesg -n 
"  runlevel (${previous}). "
                boot_mesg 
""   $ {NORMAL}
                boot_mesg_flush
                continue
            fi
        fi
        
$ {i} stop         # 脚本执行stop
        error_value
=$ {?}     # 返回值

        
if  [  " ${error_value} "  ! =   " 0 "  ] ;   then
            print_error_msg
        fi
    done
fi

# Start  all functions in this runlevel
# 开始所有S开头的脚本
for  i in  $(  ls -v  $ {rc_base} / rc $ {runlevel} . d / S*  2 >   / dev / null )          # 获得每个脚本
do
    
if  [  " ${previous} "  ! =   " N "  ] ;   then                  # 如果有前一个级别
        suffix
=$ {i #$ rc_base / rc $ runlevel . d / S[ 0 - 9 ][ 0 - 9 ]}     # 脚本文件名
        stop
=$ rc_base / rc $ runlevel . d / K[ 0 - 9 ][ 0 - 9 ] $ suffix    
        prev_start
=$ rc_base / rc $ previous . d / S[ 0 - 9 ][ 0 - 9 ] $ suffix

        [ -f 
$ {prev_start} ] && [ ! -f  $ {stop} ] && continue     # 如果前一个级别中没有该脚本的stop,则说明该进程已经存在
    fi

    check_script_status    
# 检查脚本是否存在

    case 
$ {runlevel} in     # 0或6则直接stop
        
0 | 6 )
            
$ {i} stop
            
;;
        *
)
            
$ {i}  start
            
;;
    esac
    error_value
=$ {?}

    
if  [  " ${error_value} "  ! =   " 0 "  ] ;   then
        print_error_msg
    fi
done

#   End   $ rc_base / init . d / rc
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值