控制腳本目錄/etc/rc.d,該目錄下存在各個運作級别的腳本檔案,以下是centos7為例的查詢結果:
[root@hostname centos7 root]# cd /etc/rc.d/
[root@hostname centos7 rc.d]# ls
init.d rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.local
[root@hostname centos7 rc.d]# cd rc4.d/
[root@hostname centos7 rc4.d]# ls
K50netconsole S10network S64mysqld
[root@hostname centos7 rc4.d]#
[root@hostname centos7 rc4.d]#
[root@hostname centos7 rc4.d]#
[root@hostname centos7 rc4.d]# cd /etc/rc.d/
[root@hostname centos7 rc.d]# ls
init.d rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d rc.local
[root@hostname centos7 rc.d]# cd rc0.d/
[root@hostname centos7 rc0.d]# ls
K36mysqld K50netconsole K90network
[root@hostname centos7 rc0.d]# cd ../init.d/
[root@hostname centos7 init.d]# ls
functions mysqld netconsole network README
說明:
/etc/rc.d/init.d
該檔案夾包含所有服務在各個運作等級中的全部啟動腳本。一般來說,它們都是标準的shell腳本,遵守最基本的标準。每個腳本最少接受兩個參數start和stop,它們分别代表啟動和停止服務(如網頁服務)。除此之外,init腳本通常還會接受一些額外的選項,如restart(重新開機伺服器)、status(傳回服務目前狀态)、reload(告知服務從配置檔案中重新載入配置)以及force-reload(強制服務重載它的配置)。當用不帶參數的方式運作腳本的時候,一般應該傳回一個它會接受的參數清單。
/etc/rc.d/rc0.d~/etc/rc.d/rc6.d
這些檔案夾分别包含每個運作等級對應的init腳本。在實際使用中,它們一般通過符号連結到/etc/init.d檔案夾下的實際檔案。不過要注意的是,這些檔案夾下的init腳本都有一些特别的名字,命名都以S(start)、K(kill)或D(disable)開頭,後面跟一個數字。當init進入一個運作等級的時候,它會按照數字順序運作所有以K開頭的腳本并傳入stop參數,除非對應的init腳本在前一個運作等級中沒有啟動。然後init按照數字順序運作所有以S開頭的腳本并傳入start參數。任何以D開頭的init腳本都會被忽略—這讓你可以在指定的運作等級禁止一個腳本,或者你也可以僅僅移除全部符号連結。是以如果你有兩個腳本,S01foo和S05bar,init首先會運作S01foo start,當它進入特定的運作等級後再執行S05bar start。
/etc/rc.d/rc.local
并非所有的發行版都使用了rc.local,通常它是一個留給使用者修改的shell腳本。一般會在init程序結束的時候運作它,是以你可以在這裡放一些想要運作的額外腳本,而不用再建立自己的init腳本。
/etc/rc.d/rc.sysinit
/etc/rc.d/rc.sysinit主要做在各個運作模式中相同的初始化工作,包括設定PATH、設定網絡配置(/etc/sysconfig/network)、啟動swap分區、設定/proc等等。
/etc/rc.d/rc