#chkconfig --list 查看所有服务在不同运行级别下的停启情况
#chkconfig --list xxx 查看指定服务
#chkconfig --level 3 crond off 修改服务在级别3关闭crond服务开机启动
#chkconfig crond on 修改服务在级别3、4、5 crond服务开机启动
添加自定义服务(服务管理脚本定义在/etc/init.d目录下)
#创建服务脚本
vim /etc/init.d/testsrv
#!/bin/bash
# chkconfig: - 96 3
# description: This is test service script
. /etc/init.d/functions
start(){
[ -e /var/lock/subsys/testsrv ] && exit || touch /var/lock/subsys/testsrv
echo $PATH
action "Starting testsrv"
sleep 3000 &
}
stop(){
[ -e /var/lock/subsys/testsrv ] && rm /var/lock/subsys/testsrv || exit
action "Stopping testsrv"
}
status(){
[ -e /var/lock/subsys/testsrv ] && echo "testsrv is running..." || echo
"testsrv is stopped"
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo $"Usage $0 {start|stop|status|restart}"
exit 2
esac
#加可执行权限
chmod a+x /etc/init.d/testsrv
#添加服务
chkconfig --add testsrv
#查看
chkconfig --list testsrv
testsrv 0:off 1:off 2:off 3:off 4:off 5:off 6:off
#开机启动
chkconfig testsrv on
chkconfig --list testsrv
testsrv 0:off 1:off 2:on 3:on 4:on 5:on 6:off
#启动
service testsrv start
/sbin:/usr/sbin:/bin:/usr/bin
Starting testsrv [ OK ]
#停止
service testsrv stop
Stopping testsrv [ OK ]
#删除服务
chkconfig --del testsrv