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

转载于:https://blog.51cto.com/13490688/2306730

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值