先说明一个关系:
/etc/init.d中放的是sh脚本,/etc/rc*.d中是软链接,指向/etc/init.d中的脚本
命令行下服务的手动启动:
insserv --- a low level tool used by update-rc.d which enables an installed system init script
service --- run a System V init script
invoke-rc.d --- executes System-V style init script actions
直接指定:
/etc/init.d/command {start|restart|status|stop|force-reload}
update-rc.d命令
作用:install and remove System-V style init script links
这是个perl脚本,用法如下
update-rc.d -fremove //从(所有的)运行级别配置目录中是删除指定的服务(K和S)update-rc.d start //配置服务在运行级别列表中按指定的顺序启动update-rc.d stop //配置服务在运行级别列表中指定的顺序停止
man中的:
update-rc.d [-n] [-f] name removeupdate-rc.d [-n] name defaults [NN | SS KK]update-rc.d [-n] name start|stop NN runlevel [runlevel]... start|stop NN runlevel [runlevel]... . ...update-rc.d [-n] name disable|enable [ S|2|3|4|5 ]
-n 意思是不作改变,只是看一下将要作什么
-f 强制删除符号链接,即使是/etc/init.d/中的相应脚本仍存在
附:
运行级别
- 0(关闭系统)
- 1(单用户模式,只允许root用户对系统进行维护。)
- 2 到 5(多用户模式,其中3为字符界面,5为图形界面。)
- 6(重启系统)
以apache为例:
以默认选项添加,启动在2-5, 停止在0,1,6 update-rc.d apache defaults 手动指定运行级别,20为优先级,越高越晚, 注意有点号 update-rc.d apache start 30 2 3 4 5 . stop 70 0 1 6 . 当B需要A时,设置如下: update-rc.d script_for_A defaults 80 20 update-rc.d script_for_B defaults 90 10 移除所有启动链接: update-rc.d apache remove 禁用服务: update-rc.d -f apache remove update-rc.d apache stop 20 2 3 4 5 . 安装一个系统初始化和关机脚本 update-rc.d foobar start 45 S . stop 31 0 6 . 禁用上面那个 update-rc.d -f foobar remove update-rc.d foobar stop 45 S sysv-rc-conf 命令 非常好用的工具,提供操作简单的界面