From bf2e71d76cfab59384ca2736fef9c757752bac88 Mon Sep 17 00:00:00 2001 From: Pil0tXia Date: Fri, 15 Mar 2024 18:30:07 +0800 Subject: [PATCH] refine the script --- deployment/auto-deploy-eventmesh-dashboard.sh | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/deployment/auto-deploy-eventmesh-dashboard.sh b/deployment/auto-deploy-eventmesh-dashboard.sh index 82a99c3e..01aae6c5 100644 --- a/deployment/auto-deploy-eventmesh-dashboard.sh +++ b/deployment/auto-deploy-eventmesh-dashboard.sh @@ -21,17 +21,17 @@ REPO_PATH=~/service/eventmesh-dashboard # SpringBoot process ID file path -PID_LOG=./eventmesh-dashboard-pid.log +PID_LOG=~/service/eventmesh-dashboard/deployment/eventmesh-dashboard-pid.log -# Automatic deployment log file path -AUTO_DEPLOY_LOG=./auto-deploy-eventmesh-dashboard.log +# Automatic deployment shell script log file path +AUTO_DEPLOY_LOG=~/service/eventmesh-dashboard/deployment/auto-deploy-eventmesh-dashboard.log + +# EventMesh Dashboard log file path +APP_LOG=~/service/eventmesh-dashboard/deployment/eventmesh-dashboard-$(date +"%Y-%m-%d-%H-%M-%S").log # Jar file path JAR_FILE_PATH=~/service/eventmesh-dashboard/eventmesh-dashboard-console/target/eventmesh-dashboard-console-0.0.1-SNAPSHOT.jar -# Check if the pid.log file exists, if not, create an empty file -touch $PID_LOG - # Update the git repository cd $REPO_PATH git fetch origin dev @@ -46,7 +46,7 @@ if [ $LOCAL != $REMOTE ]; then echo "$(date +"%Y-%m-%d %H:%M:%S") - change detected." >> $AUTO_DEPLOY_LOG # Terminate the old process - if [ -f $PID_LOG ]; then + if [ -s $PID_LOG ]; then PID=$(cat $PID_LOG) if [ -n "$PID" ]; then kill $PID @@ -55,11 +55,11 @@ if [ $LOCAL != $REMOTE ]; then fi fi - # Compile and package the Jar file using Maven + # Compile and package the Jar file mvn clean package # Start the springboot application and record the process id to pid.log file, redirect console logs to eventmesh-dashboard-.log file - nohup java -jar $JAR_FILE_PATH > eventmesh-dashboard-$(date +"%Y-%m-%d-%H-%M-%S").log 2>&1 & + nohup java -jar $JAR_FILE_PATH > $APP_LOG 2>&1 & echo $! > $PID_LOG # Log the event @@ -70,14 +70,17 @@ else # Log the event echo "$(date +"%Y-%m-%d %H:%M:%S") - no change detected." >> $AUTO_DEPLOY_LOG - if [ -f $PID_LOG ]; then + if [ -s $PID_LOG ]; then # If the pid.log file exists, no action is performed echo "$(date +"%Y-%m-%d %H:%M:%S") - application running, no operation performed." >> $AUTO_DEPLOY_LOG else - # If the pid.log file does not exist, start the springboot application and record the process id to pid.log file, redirect console logs to eventmesh-dashboard-.log file - nohup java -jar $JAR_FILE_PATH > eventmesh-dashboard-$(date +"%Y-%m-%d-%H-%M-%S").log 2>&1 & + # If the pid.log file does not exist, compile and package the Jar file + mvn clean package + + # Start the springboot application and record the process id to pid.log file, redirect console logs to eventmesh-dashboard-.log file + nohup java -jar $JAR_FILE_PATH > $APP_LOG 2>&1 & echo $! > $PID_LOG - + # Log the event echo "$(date +"%Y-%m-%d %H:%M:%S") - no pid.log file, start application." >> $AUTO_DEPLOY_LOG fi