码迷,mamicode.com
首页 > 系统相关 > 详细

用shell写一个服务启动脚本,速度get!

时间:2018-10-20 13:40:20      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:--   stop   desc   des   执行   rip   rtu   系统服务   失败   

制作服务启动程序:(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指令得以管理它。

用shell写一个服务启动脚本,速度get!

标签:--   stop   desc   des   执行   rip   rtu   系统服务   失败   

原文地址:http://blog.51cto.com/13490688/2306730

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!