自定义Linux service
时间:2006-12-30 来源:int345
#!/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 进行管理了。