Mik*_*kov 12
/etc/init.d/ 目录中有一些文件:
$ ls -al /etc/init.d/ | grep -i depend
-rw-r--r-- 1 root root 2739 Feb 17 05:20 .depend.boot
-rw-r--r-- 1 root root 2221 Feb 17 05:20 .depend.start
-rw-r--r-- 1 root root 1855 Feb 17 05:20 .depend.stop
Run Code Online (Sandbox Code Playgroud)
无论何时运行update-rc.d,文件都会改变。.depend.boot文件用于S级别, .depend.start用于2 3 4 5级别和.depend.stop用于0 1 6.
就我而言,我有以下顺序.depend.start:
TARGETS = killprocs motd nvidia-kernel nfs-common rsyslog privoxy virtualbox
linuxlogo acpi-fakekey binfmt-support fancontrol openvpn hddtemp cgconfig
dropbox-container dbus dnscrypt-proxy pulseaudio atd cryptmount exim4
qbittorrent-nox ddclient acpi-support smartmontools ssh ntp loadcpufreq acpid
cron rsync cgrulesengd cpufrequtils bootlogs bootchart-done single rmnologin
rc.local stop-bootlogd
Run Code Online (Sandbox Code Playgroud)
您还可以看到为什么订单以您在上面看到的方式呈现。下一行看起来像这样:
cgrulesengd: rsyslog cgconfig
Run Code Online (Sandbox Code Playgroud)
这意味着cgrulesengd需要rsyslog cgconfig事先启动。
小智 5
每个运行级别 (0 6) 都有一个文件夹 /etc/rc[N].d
在每个目录中都有以“S”或“K”开头的符号链接。"S" 开始 e "K" 停止。脚本以文件名的词法排序方式执行,换句话说,S10script 将比 S20myscript 先执行。例如 :
我们有两个简单的脚本,second.sh 脚本必须在当前运行级别的 fist.sh 脚本之后执行。
root@localhost init.d]# cat /etc/init.d/first.sh
#!/bin/bash
#
echo 'I am the first' >> /var/log/messages
root@localhost init.d]# cat /etc/init.d/second.sh
#!/bin/bash
#
echo 'I am the second' >> /var/log/messages
Run Code Online (Sandbox Code Playgroud)
我现在的水平是多少?
[root@localhost init.d]# runlevel
N 5
Run Code Online (Sandbox Code Playgroud)
现在我们需要一个符号链接,即第一个 S(N)myScript 和 S(N+1)mysecondScript:
root@localhost rc5.d]# ln -s /etc/init.d/first.sh /etc/rc5.d/S1first
root@localhost rc5.d]# ln -s /etc/init.d/second.sh /etc/rc5.d/S2second
Run Code Online (Sandbox Code Playgroud)
我们可以重新启动并检查消息日志:
[root@localhost ~]# cat /var/log/messages | grep "I am" -A 1 -B 1
Dec 13 13:53:36 localhost rpc.statd[3468]: Version 1.0.9 Starting
I am the first
Dec 13 13:53:37 localhost hcid[3532]: Bluetooth HCI daemon
--
Dec 13 13:53:40 localhost automount[3689]: lookup_read_master: lookup(nisplus): couldn't locate nis+ table auto.master
I am the second
Dec 13 13:53:41 localhost gpm[3785]: *** info [startup.c(95)]:
Run Code Online (Sandbox Code Playgroud)
在旧的 Centos5 上测试
| 归档时间: |
|
| 查看次数: |
61463 次 |
| 最近记录: |