1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #!/bin/bash app=xxx appName=${app}-1.0.0-SNAPSHOT projPath=/opt/xxx upgradePath=${projPath}/upgrade backPath=${projPath}/backup logFile=${projPath}/data/logs/${app}.log
# 检查升级文件是否存在 echo "checking upgrade file..." if [ ! -f ${upgradePath}/${appName}.jar ]; then echo "cann't found file ${upgradePath}/${appName}.jar!" exit fi
# 结束进程 pid=`ps aux | grep ${projPath}/${appName}.jar | grep -v grep | grep -v kill | awk '{print $2}'` if [ ${pid} ]; then echo "kill ${appName}!" kill -9 $pid fi
# 备份原升级文件,如果存在的话 if [ -f ${projPath}/${appName}.jar ]; then timeStr=`date +%Y%m%d%H%M%S` mv ${projPath}/${appName}.jar ${backPath}/${appName}.jar.bak_${timeStr} echo "load ${appName} success!" echo "backup ${appName} success!" fi
# 拷贝升级文件 echo "copy ${appName}.jar..." cp ${upgradePath}/${appName}.jar ${projPath}/${appName}.jar
# 启动进程 echo "start ${appName}..." nohup java -Djava.security.egd=file:/dev/./urandom -Xms512m -Xmx512m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m -jar ${projPath}/${appName}.jar --spring.profiles.active=test >/dev/null 2>&1 &
# 查看日志 # 判断当天日志文件是否存在 if [ ! -f ${logFile} ]; then # 文件不存在则创建文件,再执行tail命令 touch ${logFile} fi echo "tail -f ${logFile}"
|