6 Star 72 Fork 28

JustryDeng / notebook

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
[14]重启jar包的shell脚本.md 1.47 KB
一键复制 编辑 原始数据 按行查看 历史
JustryDeng 提交于 2023-03-21 14:27 . 常用devops示例

重启jar包的shell脚本

简述

代码

#! /bin/bash
#jar名称
JAR_PATH=pension-basic-2.0.2.jar
# 输出启动前的进程情况
echo '启动前的进程情况'
echo $(ps -ef | grep $JAR_PATH | grep -v grep)
# 'ps -ef | grep pension-basic'表示: 找关键字"pension-basic"相关进程,
# 'grep -v grep'表示:在'ps -ef | grep pension-basic'的结果基础上,通过-v取反,不要那些带有grep关键字的行
# 'ps -ef | grep pension-basic | grep -v grep'结果形如:  root     13642     1  1 Dec02 ?        03:55:09 java -Xms1000m -Xmx1000m -jar pension-basic-2.0.2.jar --spring.profiles.active=test
#  awk '{ print $2 }'表示:获取第二个参数,这里即为13642
PID=$(ps -ef | grep $JAR_PATH | grep -v grep | awk '{ print $2 }')
# -z,判断是否存在
if [ -z $PID ]
then
 echo Application is already stopped
else
 echo kill $PID
 kill -9 $PID
fi
# 启动项目(如果的shell脚本与jar包不在同一个位置,那么这里启动时需要定位到jar包对应的位置才行)
nohup java -jar $JAR_PATH >/dev/null 2>&1 &
# 输出启动后的进程情况
echo '启动后的进程情况'
echo $(ps -ef | grep $JAR_PATH | grep -v grep)

测试

image-20221214160528071

相关资料

1
https://gitee.com/JustryDeng/notebook.git
git@gitee.com:JustryDeng/notebook.git
JustryDeng
notebook
notebook
master

搜索帮助