#!/bin/bash
#name:jar包启动脚本;
#date:2020-02-21
#author:shuai
#此处修改脚本名称:
APP_NAME=项目名称.jar
#脚本菜单项
usage() {
echo "Usage: sh start.sh [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
#此处注意修改jar和log文件文件位置:
nohup java -jar /项目路径/$APP_NAME > log.log 2>&1 &
#此处打印log日志:
tail -f /项目路径/log.log
fi
}
#停止脚本
stop(){
is_exist
if [ $? -eq "0" ]; then
kill -9 $pid
else
echo "${APP_NAME} is not running"
fi
}
#显示当前jar运行状态
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
start
}
case "$1" in
"start")
start
;;
"stop")
stop
;;
"status")
status
;;
"restart")
restart
;;
*)
usage
;;
esac
09-15
334
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
06-28
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交