用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指令得以管理它。

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