用shell寫一個服務啓動腳本,速度get!

製作服務啓動程序:(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指令得以管理它。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章