当前位置:首页 > 编程笔记 > 正文
已解决

linux环境执行jar脚本

来自网友在路上 169869提问 提问时间:2023-10-25 06:21:51阅读次数: 69

最佳答案 问答题库698位专家为你答疑解惑

一、前言

平常工作中,我们的开发的项目部署到linux环境,以jar包的方式运行,涉及jar包的启动、停止、查看状态等,我们可以通过脚本的方式进行维护,减少自己敲打一长串的命令少敲一个字母或者多敲一个字母,方便维护。

二、脚本

vim  app.sh

#!/bin/bashappName=xxxx.jar
if [ -z $appName ]
thenecho "Please check that this script and your jar-package is in the same directory!"exit 1
fikillForceFlag=$2function start()
{count=`ps -ef |grep java|grep $appName|wc -l`if [ $count != 0 ];thenecho "Maybe $appName is running, please check it..."elseecho "The $appName is starting..."nohup java -jar $appName --spring.profiles.active=test >log.out 2>&1 &fi
}function stop()
{appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`if [ -z $appId ]thenecho "Maybe $appName not running, please check it..."elseecho -n "The $appName is stopping..."if [ "$killForceFlag" == "-f" ]thenecho "by force"kill -9 $appIdelseechokill $appIdfifi
}function status()
{appId=`ps -ef |grep java|grep $appName|awk '{print $2}'`if [ -z $appId ]thenecho -e "\033[31m Not running \033[0m"elseecho -e "\033[32m Running [$appId] \033[0m"fi
}function restart()
{stopfor i in {3..1}doecho -n "$i "sleep 1doneecho 0start
}function help()
{echo "Usage: $0 {start|stop|restart|status|stop -f}"echo "Example: $0 start"exit 1
}function taillog()
{tail -f -n 1000 log.out
}case $1 instart)start;;stop)stop;;restart)restart;;status)status;;taillog)taillog;;*)help;;
esac

三、授权及命令

chmod   +x      app.sh

启动:app.sh  start    

停止:app.sh  stop -f

查看状态 app.sh  status

查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"linux环境执行jar脚本":http://eshow365.cn/6-23959-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!