echo "备份jar"
cd /home/
timestamp=$(date +%Y%m%d%H%M%S)
bak_name=xxxxxx-${timestamp}.jar
mv xxxxx.jar ./bak/xxxxx-${timestamp}.jar
后台启动jar脚本
cd /home/ cat /dev/null > log nohup sh startJar.sh >log &startJar.sh
#!/bin/bash
source /etc/profile
pid=`ps -ef|grep xxxxxx.jar| grep -v grep | awk '{print $2}'`
echo "部署前的pid进程 :$pid"
if [ -n "$pid" ]
then
kill -9 $pid
else
echo "进程没有启动"
fi
sleep 5s
nohup java -jar xxxxxx.jar --spring.profiles.active=dev &
echo "脚本执行完毕"
sleep 5s
pid=`ps -ef|grep gov-big-data-exchange-api.jar | grep -v grep | awk '{print $2}'`
if [ -n "$pid" ]
then
echo "部署后的pid进程 :$pid"
echo "启动成功"
else
echo "进程没有启动"
fi
脚本步骤
- 备份原jar包
- 获取jar包启动的进程pid ps -ef|grep xxxxxx.jar| grep -v grep | awk ‘{print
$2}’ - 后台运行jar包 nohup java -jar xxxxxx.jar --spring.profiles.active=dev &
- 睡5s,检测进程状态
第一种:cp /dev/null nohup.out
第二种:cat /dev/null > nohup.out
date "+%Y-%m-%d %H:%M:%S" 2016-09-08 13:48:24
date +%Y%m%d%H%M%S 20220519174912



