Linux文件目錄/etc/init和/etc/init.d的前世此生

##二者對比## 這段時間看linux內核啓動過程,啓動先要加載init進程(即1號進程),而後是按運行級別去執行相關腳本和配置。可是cd /etc目錄後會發現兩個和init相關的目錄:/etc/init和/etc/init.d。不少文章都介紹了/etc/init/ 和 /etc/init.d/文件目錄的區別,其實對它們的來源和實質並無說清楚。看到下面這幾段話,仍是老外描述的比較清楚 【1】linux

/etc/init.d contains scripts used by the System V init tools (SysVinit). This is the traditional service management package for Linux, containing the init program (the first process that is run when the kernel has finished initializing) as well as some infrastructure to start and stop services and configure them. Specifically, files in /etc/init.d are shell scripts that respond to start, stop, restart, and (when supported) reload commands to manage a particular service. These scripts can be invoked directly or (most commonly) via some other trigger (typically the presence of a symbolic link in/etc/rc?.d/).shell

/etc/init.d裏的shell腳本(SysVinit工具所包含的函數庫)可以響應start,stop,restart,reload命令來管理某個具體的應用。好比常常看到的命令: /etc/init.d/networking start 這些腳本也可被其餘trigger直接激活執行,這些trigger被軟鏈接在/etc/rcN.d/中。這些原理彷佛能夠用來寫daemon程序,讓某些程序在開關機時運行。ubuntu

/etc/init contains configuration files used by Upstart. Upstart is a young service management package championed by Ubuntu. Files in /etc/init are configuration files telling Upstart how and when tostart, stop, reload the configuration, or query the status of a service. As of lucid(清楚的), Ubuntu is transitioning from SysVinit to Upstart , which explains why many services come with SysVinit scripts even though Upstart configuration files are preferred. In fact, the SysVinit scripts are processed by a compatibility layer in Upstart.app

/etc/init包含的是Upstart 【2】(Sysinit的替代版本)的配置文件,和/etc/init.d的做用幾乎差很少。這樣彷佛/etc/init能夠看做/etc/init.d的演化版本。而SysVinit腳本是和新的Upstart兼容的。這就是這兩個文件目錄的來歷和前世此生。less

##起名的講究:Our ancestors [3]##ide

.d in directory names typically indicates a directory containing many configuration files or scripts for a particular situation . This structure is usually used when each entry in the directory is provided by a different source, so that each package can deposit(存放) its own plug-in without having to parse(分析) a single configuration file to reference itself. In this case, it just happens that 「init」 is a logical name for the directory, SysVinit came first and used init.d, and Upstart used plain init for a directory with a similar purpose (it would have been more 「mainstream」(主流的?Chinglish?), and perhaps less arrogant(傲慢的), if they'd used /etc/upstart.d instead).函數

.d文件夾主要是爲了方便和清楚的邏輯描述而命名成這樣有點不三不四的(在我看來)。在這裏,init就是這個目錄的邏輯名字。SysVinit came first and used init.d, and Upstart used plain init for a directory with a similar purpose。 至於最後一句,就是調侃了:關於版本變遷的傲慢與偏見。Or put it in other words, Our ancestors。工具

##Reference## [1].http://askubuntu.com/questions/5039/what-is-the-difference-between-etc-init-and-etc-init-d [2].http://zhumeng8337797.blog.163.com/blog/static/10076891420123364928269 [3].http://en.wikipedia.org/wiki/Our_Ancestorsthis

相關文章
相關標籤/搜索