关于/etc/rcX.d/里的脚本文件的问题

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
再臭0
帖子: 39
注册时间: 2010-06-03 13:59

关于/etc/rcX.d/里的脚本文件的问题

#1

帖子 再臭0 » 2010-11-01 14:46

做了个关于runlevel的实验,发现每次用init命令切换runlevel(从A到B)时,rcB.d/下的文件都会被执行一遍,不论K开头还是S开头(先K后S)。。。(原先我以为会运行rcA.d下的K和rcB.d下的S :em03
我还发现。。。从关机到启动init 2(默认)的时候,不会执行该文件夹下以K带头的脚本(这很正常,刚开机没什么可以kill的。。。)

由此发现 init X 命令只是把X下的所有脚本都执行一遍,不论S(tart)还是K(ill),都只是执行一遍而已(开机时例外,不执行K开头的)。
但问题就来了,为什么有 K开头的和S开头的链接文件却指向同一个脚本 ? 它们真的能因为文件名不同而分别被kii or start 吗?????

求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教求教
做了这个实验午饭都没吃。。。。 :em06
再臭0
帖子: 39
注册时间: 2010-06-03 13:59

Re: 关于/etc/rcX.d/里的脚本文件的问题

#2

帖子 再臭0 » 2010-11-01 18:57

诶,没有人吗?论坛的大大们???
头像
kingkongmok
帖子: 340
注册时间: 2006-03-23 14:48

Re: 关于/etc/rcX.d/里的脚本文件的问题

#3

帖子 kingkongmok » 2010-11-01 20:52

代码: 全选

$ cat /etc/rc2.d/README 
The scripts in this directory are executed each time the system enters
this runlevel.

The scripts are all symbolic links whose targets are located in
/etc/init.d/ .

To disable a service in this runlevel, rename its script in this
directory so that the new name begins with a 'K' and a two-digit
number, and run 'update-rc.d script defaults' to reorder the scripts
according to dependencies.  A warning about the current runlevels
being enabled not matching the LSB header in the init.d script will be
printed.  To re-enable the service, rename the script back to its
original name beginning with 'S' and run update-rc.d again.

For a more information see /etc/init.d/README.
再臭0
帖子: 39
注册时间: 2010-06-03 13:59

Re: 关于/etc/rcX.d/里的脚本文件的问题

#4

帖子 再臭0 » 2010-11-01 21:48

kingkongmok 写了:

代码: 全选

$ cat /etc/rc2.d/README 
The scripts in this directory are executed each time the system enters
this runlevel.

The scripts are all symbolic links whose targets are located in
/etc/init.d/ .

To disable a service in this runlevel, rename its script in this
directory so that the new name begins with a 'K' and a two-digit
number, and run 'update-rc.d script defaults' to reorder the scripts
according to dependencies.  A warning about the current runlevels
being enabled not matching the LSB header in the init.d script will be
printed.  To re-enable the service, rename the script back to its
original name beginning with 'S' and run update-rc.d again.

For a more information see /etc/init.d/README.

额。。。。额。。。。。。额。。。。。。
能不能说说? 看不懂。。。(羞耻感~~)
action_reg
帖子: 40
注册时间: 2010-07-26 22:56

Re: 关于/etc/rcX.d/里的脚本文件的问题

#5

帖子 action_reg » 2010-11-01 22:08

ubuntu 10.04 以上/etc/init.d /etc/rc*.d 的机制取消了,是为了兼容才保留的。看/etc/init下的。删除试试
再臭0
帖子: 39
注册时间: 2010-06-03 13:59

Re: 关于/etc/rcX.d/里的脚本文件的问题

#7

帖子 再臭0 » 2010-11-02 16:57

action_reg 写了:ubuntu 10.04 以上/etc/init.d /etc/rc*.d 的机制取消了,是为了兼容才保留的。看/etc/init下的。删除试试
额??
为了兼容啊?
那现在是什么机制?
54yuri
帖子: 1
注册时间: 2012-02-03 16:22

Re: 关于/etc/rcX.d/里的脚本文件的问题

#8

帖子 54yuri » 2012-02-03 16:58

A) 老的机制是这样 -- redhat 、centos上也是如此:
系统启动的时候根据如果 是K开头就传stop/是S开头就传start 的参数给 /etc/rc[runlevel].d 下的相应脚本,所以该脚本无论如何都要实现这两个参数对应的功能,具体请看每个对应脚本,linux只负责帮你启动,不负责你的服务到底怎么启动,启动是否成功了都有该脚本自己负责。

B)楼上的兄弟说的新机制, 除了新服务是靠在 /etc/init/ 注册自己的xxx.conf 启动, 老服务还是最终要考老机制去调用 /etc/rc[runlevel].d/ 下的一个个脚本, 谁去启动这个老机制? 是/etc/init.d/rc (注意不是/etc/init), 根源在于rc 在/etc/init/下也向其他新服务一样注册了自己conf -- /etc/init/rc.conf , 大家打开这位文件即可,看到最后一句是 exec /etc/init.d/rc $RUNLEVEL, 明白了吧,然后看到/etc/init.d/rc 文件就能明白A)当中所说

大致过程是, ubuntu 启动新机制 ==> 分别启动/etc/init/Xxx.conf ==> 启动到了/etc/init/rc.conf ==> 调用 /etc/init.d/rc ==> 启动旧机制 ==> 是K开头就传stop/是S开头就传start 的参数给 /etc/rc[runlevel].d 下的相应脚本

如果有错误请指出。。。
头像
susbarbatus
帖子: 2966
注册时间: 2010-04-10 16:14
系统: Arch Linux

Re: 关于/etc/rcX.d/里的脚本文件的问题

#9

帖子 susbarbatus » 2012-02-03 17:42

好复杂…还是arch比较萌
沉迷将棋中……
回复