之前在Linux部署SpringBoot项目用的是复杂的命令,后来网上搜到有位大神写的shell脚本,颇为好用,后来忘记shell脚本放哪了。在这里写个日志记录一下,避免以后再找不到了。
新建一个app.sh文件,修改一下自己的jar包存放路径。
#!/bin/bash
#jar包存放路径
APP_NAME=senwill-0.0.1-SNAPSHOT.jar
#使用说明,用来提示输入参数
usage() {
echo "请选择一项操作执行 [start|stop|restart|status]"
exit 1
}
#检查程序是否在运行
is_exist(){
pid=`ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'`
#如果不存在返回1,存在返回0
if [ -z "${pid}" ]; then
return 1
else
return 0
fi
}
#启动方法
start(){
is_exist
if [ $? -eq 0 ]; then
echo "${APP_NAME} is already running. pid=${pid}"
else
nohup java -jar ${APP_NAME} >log.out 2>&1 &
fi
}
#停止方法
stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
else
echo "${APP_NAME} is not running"
fi
}
#输出运行状态
status(){
is_exist
if [ $? -eq "0" ]; then
echo "${APP_NAME} is running. Pid is ${pid}"
else
echo "${APP_NAME} is NOT running."
fi
}
#重启
restart(){
stop
sleep 5
start
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
1、查看项目运行状态
sh app.sh status
2、启动、停止、重启
sh app.sh start
sh app.sh stop
sh app.sh restart
转载自:Linux shell脚本启动停止重启springboot jar包 – it610.com
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/151166.html