linux-ubuntu与Debian系统中的update-rc.d


在ubuntu下开机自启动程序流程:

1.编写服务脚本放在/etc/init.d下,例如servicetest
/etc/init.d/servicectest
2.在/etc/rc*.d中制作相关的link。K开头是kill, S开头是start, 数字顺序代表启动的顺序。
update-rc.d 可以帮你的忙。
例如:
在/etc/init.d 中建立一个叫作servicetest的script , 然后
update-rc.d servicetest defaults

就会产生以下链結:

Adding system startup for /etc/init.d/servicetest ...
/etc/rc0.d/K20servicetest -> ../init.d/servicetest
/etc/rc1.d/K20servicetest -> ../init.d/servicetest
/etc/rc6.d/K20servicetest -> ../init.d/servicetest
/etc/rc2.d/S20servicetest -> ../init.d/servicetest
/etc/rc3.d/S20servicetest -> ../init.d/servicetest
/etc/rc4.d/S20servicetest -> ../init.d/servicetest
/etc/rc5.d/S20servicetest -> ../init.d/servicetest


=========华丽丽的分割线 呵呵============

基本知识之update-rc.d

update-rc.d命令,是用来自动的升级System V类型初始化脚本,
简单的讲就是,哪些东西是你想要系统在引导初始化的时候运行的,哪些是希望在关机或重启时停止的,可以用它来帮你设置。
这些脚本的连接位于/etc/rc*.d/LnName,对应脚本位于/etc/init.d/Script-name.
ubuntu与Debian 的update-rc.d与RH的chkconfig工具相类似。
然而chkconfig是一个二进制程序,而update-rc.d是一个Perl脚本。
这些工具有不同的命令行选项,但是却执行类似的功能。


1.添加服务
[1]
# sudo update-rc.d apache2 defaults
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K20apache2 -> ../init.d/apache2
/etc/rc1.d/K20apache2 -> ../init.d/apache2
/etc/rc6.d/K20apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S20apache2 -> ../init.d/apache2
[2]
# sudo update-rc.d apache2 defaults 91
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K91apache2 -> ../init.d/apache2
/etc/rc1.d/K91apache2 -> ../init.d/apache2
/etc/rc6.d/K91apache2 -> ../init.d/apache2
/etc/rc2.d/S91apache2 -> ../init.d/apache2
/etc/rc3.d/S91apache2 -> ../init.d/apache2
/etc/rc4.d/S91apache2 -> ../init.d/apache2
/etc/rc5.d/S91apache2 -> ../init.d/apache2
[3]
#sudo update-rc.d apache2 defaults 20 80
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K80apache2 -> ../init.d/apache2
/etc/rc1.d/K80apache2 -> ../init.d/apache2
/etc/rc6.d/K80apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S20apache2 -> ../init.d/apache2
[4]
# sudo update-rc.d apache2 start 20 2 3 4 5 . stop 80 0 1 6 .
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K80apache2 -> ../init.d/apache2
/etc/rc1.d/K80apache2 -> ../init.d/apache2
/etc/rc6.d/K80apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S20apache2 -> ../init.d/apache2
[5]
# sudo update-rc.d apache2 start 20 2 3 4 . start 30 5 . stop 80 0 1 6 .
Adding system startup for /etc/init.d/apache2 ...
/etc/rc0.d/K80apache2 -> ../init.d/apache2
/etc/rc1.d/K80apache2 -> ../init.d/apache2
/etc/rc6.d/K80apache2 -> ../init.d/apache2
/etc/rc2.d/S20apache2 -> ../init.d/apache2
/etc/rc3.d/S20apache2 -> ../init.d/apache2
/etc/rc4.d/S20apache2 -> ../init.d/apache2
/etc/rc5.d/S30apache2 -> ../init.d/apache2

例如:
update-rc.d script-name start 90 1 2 3 4 5 . stop 52 0 6 .
start 90 1 2 3 4 5 . : 表示在1、2、3、4、5这五个运行级别中,按先后顺序,由小到大,第90个开始运行这个脚本。
stop 52 0 6 . :表示在0、6这两个运行级别中,按照先后顺序,由小到大,第52个停止这个脚本的运行。


2.删除服务
# sudo update-rc.d 服务名 remove
update-rc.d removes any links in the /etc/rcrunlevel.d directories to the script /etc/init.d/name.
The script  must  have  been deleted already - update-rc.d checks for this.
# sudo -f update-rc.d 服务名 remove      
-f     Force removal of symlinks even if /etc/init.d/name still exists
# sudo update-rc.d 服务名 stop 80 0 1 2 3 4 5 6 .
This command will only disable the service until next time the service is upgraded.
If you want to make sure the service won't be re-enabled upon upgrade, you should also type the above.

例如:
update-rc.d -f foobar remove
update-rc.d foobar stop 20 2 3 4 5 .

3.临时重启服务:
/etc/init.d/服务名 restart
4.临时关闭服务:
/etc/init.d/服务名 stop
5.临时启动服务:
/etc/init.d/服务名 start


FILES
       /etc/init.d/
              The directory containing the actual init scripts.

       /etc/rc*.d/
              The directories containing the links used by init and managed by
              update-rc.d.

       /etc/init.d/skeleton
              Model for use by writers of init.d scripts.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值