update-rc.d为debian/ubuntu管理开机启动的工具,类似于chkconfig
详细用法可查阅帮助信息
update-rc.d --help
查看系统当前的初始化服务
$ ls /etc/init.d/ $ ls /etc/rc?.d
增加或删除开机启动项
update-rc.d -f <service> remove # 删除开机启动项服务 update-rc.d <service> start <order> <runlevels> # 新增系统启动项服务 update-rc.d <service> stop <order> <runlevels> # 停用某系统启动项
修改启动项的启动级别
update-rc.d [-n] name disable|enable [ S|2|3|4|5 ]
例子
update-rc.d php-fpm defaults # 新增系统启动项,开机即运行php-fpm服务 update-rc.d -f apache2 remove # 将apache2从启动项里删除
update-rc.d minecraft_server defaults #开机运行minecraft update-rc.d -f minecraft_server remove #将minecraft从启动项移除
如将pptpd从开机启动中移除
# update-rc.d -n -f pptpd remove Removing any system startup links for /etc/init.d/pptpd ... /etc/rc1.d/K20pptpd /etc/rc2.d/S20pptpd /etc/rc3.d/S20pptpd /etc/rc4.d/S20pptpd /etc/rc5.d/S20pptpd
自己编译安装的想要加到开机运行服务中,还可以编写一个abc文件,具体可参考其他/etc/init.d/中的文件,放到/etc/init.d/abc
#! /bin/sh # /etc/init.d/abc # # Some things that run always touch /var/lock/abc # Carry out specific functions when asked to by the system case "$1" in start) echo "Starting script abc " echo "Could do more here" ;; stop) echo "Stopping script abc" echo "Could do more here" ;; *) echo "Usage: /etc/init.d/abc {start|stop}" exit 1 ;; esac exit 0
给其加上权限
chmod 755 /etc/init.d/abc
添加启动链接即可
# update-rc.d abc defaults
Leave a Reply