用shell写一个服务启动脚本,速度get!
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用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指令得以管理它。
以上是关于用shell写一个服务启动脚本,速度get!的主要内容,如果未能解决你的问题,请参考以下文章
Linux的shell脚本文件中怎么写多个自动启动的系统服务
想请大神写一个在linux环境下用shell脚本控制jar的启动和停止,类似于一个后台服务那种的。