Nohup 部署更新升级Java后端项目
#!/bin/bash
JAR_NAME="lit-message.jar"
JAR_PATH="/tmp/$JAR_NAME"
TARGET_DIR="/tmp/"
PID_FILE="nohup.pid"
LOG_FILE="LitMessage.log"
if [ -f "/mnt/000.Docker/003.Lit-Message/$PID_FILE" ]; then
read -r pid < "/mnt/000.Docker/003.Lit-Message/$PID_FILE"
if kill -0 "$pid" 2>/dev/null; then
kill "$pid"
echo "Old process with PID $pid terminated."
else
echo "No process found with PID $pid."
fi
rm -f "/mnt/000.Docker/003.Lit-Message/$PID_FILE"
fi
rm -f "/mnt/000.Docker/003.Lit-Message/$JAR_NAME"
cp "$JAR_PATH" "/mnt/000.Docker/003.Lit-Message/"
nohup java -jar "/mnt/000.Docker/003.Lit-Message/$JAR_NAME" --spring.active=dev > "/mnt/000.Docker/003.Lit-Message/$LOG_FILE" 2>&1 &
echo $! > "/mnt/000.Docker/003.Lit-Message/$PID_FILE"
echo "New process started with PID $!"
评论区