本文转载自http://blog.csdn.net/kkdelta/article/details/7748842
service xxx启动 /etc/init.d/ 目录下的xxx脚本
如一个脚本名为 mysvc保存在/etc/init.d/下可以用 service mysvc 运行mysvc脚本echo passed in option $0 $1
if [ $1 = "start" ]
then
echo myservice started........................................
elif [ $1 = "stop" ]
then
echo myservice stoped........................................
else
echo myservice not supported option........................................
fi
[root@localhost init.d]# service mysvc start
passed in option /etc/init.d/mysvc start
myservice started........................................
[root@localhost init.d]# service mysvc stop
passed in option /etc/init.d/mysvc stop
myservice stoped........................................
[root@localhost init.d]# service mysvc xxx
passed in option /etc/init.d/mysvc xxx
myservice not supported option........................................
如何增加一个服务在机器启动时启动:
1.服务脚本必须存放在/etc/ini.d/目录下;
2.chkconfig --add servicename
在chkconfig工具服务列表中增加此服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了;
3.chkconfig --level 35 servicename on
修改服务的默认启动等级。
脚本需要有下面的的内容,否则会 service servicename does not support chkconfig
# chkconfig: - 85 15
# description: description for the service
#上面为固定格式:- 表示运行级别(所有),85表示开机执行顺序,15为关机顺序,完整内容如下