jar在linux上运行脚本 #start #stop #restart

发布时间:2022-06-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了jar在linux上运行脚本 #start #stop #restart脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
#!/bin/bash
#name:jar包启动脚本;
#date:2019-8-26;
#author:Yu-Luozi

#此处修改脚本名称:
JAR_PATH=/usr/local/getto/
LOG_PATH=/tmp/
APP_NAME=gopoint-service-1.0-SNAPSHOT.jar
LOG_NAME=getto.log
#脚本菜单项
usage() {
 echo "Usage: sh 脚本名.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 "$JAR_PATH$APP_NAME" > bootdolog.file   2>&1 &
#此处打印log日志:
 tail -f "$LOG_PATH$LOG_NAME"
 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

 

脚本宝典总结

以上是脚本宝典为你收集整理的jar在linux上运行脚本 #start #stop #restart全部内容,希望文章能够帮你解决jar在linux上运行脚本 #start #stop #restart所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: