实现脚本如下:
vim auth.sh#!/bin/shname=auth-two-app.jardocker exec -i jar bash<<'EOF'pid=`ps -ef|grep 'auth-two-app.jar'|grep -v grep|awk '{print }'`cd /vrgv/jar/2.0/auth-two-app/if [ -n "${pid}" ];then kill -9 ${pid} echo "Process $name killed!" nohup java -jar -Xms265M -Xmx512M -Duser.timezone=Asia/ShangHai auth-two-app.jar > /vrgv/jar/2.0/logs/auth-two-app.log 2>&1 & echo "ReStart $name Success!"else nohup java -jar -Xms265M -Xmx512M -Duser.timezone=Asia/ShangHai auth-two-app.jar > /vrgv/jar/2.0/logs/auth-two-app.log 2>&1 & echo "Start $name Success!"fiexitEOF
阐明脚本:
1.定义了一个变量为jar包名称
2.进入名称为jar的容器
3.截取jar包名称的PID进程号
4.进入jar包目录,判断当前这个jar包PID进程号是否存在,存在杀去世启动,不存在直接启动,并重定向日志输入位置