Shell脚本-Jar启动停止重启
一、场景
测试过程中,需要反复修改配置,调试
重复输入命令过于麻烦
二、简单脚本
重启Jar:./do.sh restart
#!/bin/bash
app="api-dev.jar"
app_start(){
echo "${app}启动中..."
nohup java -jar $app &
echo "${app}启动成功"
}
app_stop(){
pid=$(ps -aux | grep $app | grep -v grep | awk '{print $2}')
if [ $pid ];then
echo "${app}正在运行,停止中…"
kill -9 $pid
echo "${app}服务已停止"
else
echo "${app}服务未运行"
fi
}
# 针对传入参数判断
if [ $1 == "start" ] ; then
app_start
elif [ $1 == "stop" ] ; then
app_stop
elif [ $1 == "restart" ] ; then
app_stop
app_start
else
echo "请传入参数:start/stop/restart"
fi

浙公网安备 33010602011771号