以下代码完整摘录自:http://blog.csdn.net/sherry_qin/article/details/48267991

#! /bin/bash                                                         
### BEGIN INIT INFO
#Provides: touchfile
#Required-Start: $all
#Required-Stop: $all
#Default-Start: 2 3 4 5
#Default-Stop: 0 1 6
#Short-Description: Run Touchfile
#Description: Run Touchfile
### END INIT INFO
TOUCHFILE="/var/tmp/touch.file"
case "$1" in
start)
echo "Creating $TOUCHFILE"
touch $TOUCHFILE
;;
stop)
echo "Removing $TOUCHFILE"
touch $TOUCHFILE
;;
restart)
echo "Recreating $TOUCHFILE"
rm $TOUCHFILE
touch $TOUCHFILE
;;
reload)
echo "Re-Touching $TOUCHFILE"
touch $TOUCHFILE
;;
*)
echo "Usage: touchfile.sh <start|stop|restart|reload>"
;;
esac
exit 0

复制shll到/etc/init.d/目录下并赋予可执行权限即可通过命令启动终止服务。
Debian类通过 update-rc.d 添加为服务,可以设置开机自启动。
CentOS类通过 chkconfig 添加为服务,可以设置开机自启动。

Related Posts: Linux编写简单的启动脚本 :

留言

avatar