- 论坛徽章:
- 0
|
1.写一个脚本接受 start,stop 等等参数。比如
FileName:test
#!/bin/bash
# source function library
. /etc/rc.d/init.d/functions
usage(){
echo " usage:$0 {start|stop|restart} "
}
start(){
echo "Start."
}
stop(){
echo "Stop."
}
restart(){
stop
start
}
#main function
case $1 in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
usage
;;
esac
2.将脚本放进/etc/init.d目录下,此时就能用 service test start 来进行管理了。
3.运行chkconfig --list test,会出现错误提示:
service test does not support chkconfig
4.在代码头部加入注释
# chkconfig: 345 85 15
# description: Thisis a test service.
这个注释表示test服务在运行级别345下自动启动(/etc/rc.d/下 rc3.d rc4.d rc5.d都用相应链接到init.d/test),启动的优先级是85,停止的优先级是15。这样就能自动在相应的rc#.d/生成 S##test和K##test了。
这时就能用 chkconfig 和 ntsysv 进行管理了。
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/27464/showart_223613.html |
|