Linux文件目录/etc/init和/etc/init.d的前世今生

两者对比

这段时间看linux内核启动过程,启动先要加载init进程(即1号进程),然后是按运行级别去执行相关脚本和配置。但是cd /etc目录后会发现两个和init相关的目录:/etc/init和/etc/init.d。很多文章都介绍了/etc/init/ 和 /etc/init.d/文件目录的区别,其实对它们的来源和实质并没有说清楚。看到下面这几段话,还是老外描述的比较清楚 【1】

/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/).

/etc/init.d里的shell脚本(SysVinit工具所包含的函数库)能够响应start,stop,restart,reload命令来管理某个具体的应用。比如经常看到的命令: /etc/init.d/networking start 这些脚本也可被其他trigger直接激活执行,这些trigger被软连接在/etc/rcN.d/中。这些原理似乎可以用来写daemon程序,让某些程序在开关机时运行。

/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.

/etc/init包含的是Upstart 【2】(Sysinit的替代版本)的配置文件,和/etc/init.d的作用几乎差不多。这样似乎/etc/init可以看作/etc/init.d的演化版本。而SysVinit脚本是和新的Upstart兼容的。这就是这两个文件目录的来历和前世今生。


起名的讲究:Our ancestors [3]

.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。 至于最后一句,就是调侃了:关于版本变迁的傲慢与偏见。


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_Ancestors



Previous     Next
/
Published under (CC) BY-NC-SA in categories linux  tagged with linux