#!/usr/bin/env bash app_name='feifan-server' module_name='admin' current_time=$(date +"%Y-%m-%d %H:%M:%S") port=48080 pid=$(lsof -ti :$port) # 备份原来的jar包 cd /data/projects/backend/${module_name} mv ${app_name}.jar ${app_name}-${current_time}.jar pwd ls cd /data/jenkins_home/workspace/feifan-backend-zx-${module_name}/${app_name}/target pwd ls # 获取jar包, 直接运行 echo "--- 开始执行 ${app_name} 项目 ---" if [ -z "${pid}" ]; then echo "端口 ${port} 未被占用。" else kill -9 ${pid} echo "进程 ${pid} 已被终止。" fi echo '----启动项目 60s后结束控制台信息----' mv ./${app_name}.jar /data/projects/backend/${module_name} cd /data/projects/backend/${module_name} nohup /usr/local/jar/jdk1.8.0_371/bin/java -jar ${app_name}.jar > nohup.log 2>&1 & timeout 60s tail -f -n 1000 nohup.log echo '----项目启动成功----'