製作服務啓動程序:(case+if)
vi /etc/init.d/myprog
#!/bin/bash
#chkconfig:35 90 10
#description:Startup script for myprog Server
case "$1" in
start)
if [ -f /opt/test ];then
echo "myprog服務已經啓動 [失敗]"
else
echo "正在啓動 myprog 服務 [確定]"
touch /opt/test
fi
;;
stop)
if [ -f /opt/test ];then
echo "正在停止 myprog 服務 [確定]"
rm -rf /opt/test
else
echo "myprog服務已經停止 [失敗]"
fi
;;
restart)
echo "正在重啓 myprog 服務 [確定]"
;;
status)
if [ -f /opt/test ];then
echo "myprog服務正在運行"
else
echo "myprog服務已經停止"
fi
;;
*)
echo "用法:$0 {start |stop |restart}"
;;
esac
保存退出
chmod +x /etc/init.d/myprog ---增加執行權限
chkconfig --add myprog ---添加到系統服務中,增加所指定的系統服務,讓chkconfig指令得以管理它。