linux开机启动 debin,Debian开机启动管理

Linux下,services的启动、停止等通常是通过/etc/init.d的目录下的脚本来控制的。

在启动或改变运行级别是在/etc/rcX.d中来搜索脚本。其中X是运行级别。

比如Apache2,安装完成后,默认或启动。比如我安装了vagrant的LMPA的box。需要禁止掉自启动,就需要禁止掉这个服务,然后在需要的时候使用

/usr/sbin/apachectl start #/etc/init.d/apache2 start

在debian中使用 update-rc.d命令来实现

update-rc.d [-n] [-f] remove

update-rc.d [-n] defaults [NN | SS KK]

update-rc.d [-n] start|stop NN runlvl [runlvl] [...] .

update-rc.d [-n] disable|enable [S|2|3|4|5]

-n: not really

-f: force

删除服务

update-rc.d -f apache2 remove # -f 为强制删除

添加服务

update-rc.d apache2 defaults

并且可以指定该服务的启动顺序:

update-rc.d apache2 defaults 90

还可以更详细的控制start与kill顺序:

update-rc.d apache2 defaults 20 80

其中前面的20是start时的运行顺序级别,80为kill时的级别。也可以写成:

update-rc.d apache2 start 20 2 3 4 5 . stop 80 0 1 6 .

其中0~6为运行级别。 update-rc.d命令不仅适用Linux服务,编写的脚本同样可以用这个命令设为开机自动运行

在debian6中使用update-rc.d会报错,如下:

update-rc.d: using dependency based boot sequencing

可以使用 insserv 命令来代替 update-rc.d

insserv [] [init_script|init_directory]

Available options:

-h, --help This help.

-r, --remove Remove the listed scripts from all runlevels.

-f, --force Ignore if a required service is missed.

-v, --verbose Provide information on what is being done.

-p , --path Path to replace /etc/init.d.

-o , --override Path to replace /etc/insserv/overrides.

-c , --config Path to config file.

-n, --dryrun Do not change the system, only talk about it.

-d, --default Use default runlevels a defined in the scripts

比如

insserv -r apache2

0b1331709591d260c1c78e86d0c51c18.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值