##二者对比## 这段时间看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