From c00a0f1ac26ca1f1681edb131791ec63ea17e342 Mon Sep 17 00:00:00 2001 From: Pil0tXia Date: Sun, 31 Mar 2024 19:43:57 +0800 Subject: [PATCH] [ISSUE #81] Reduce the probability of compilation jams and abnormal application exits (#82) * Add line number to log output * No need to chmod anymore * Exclude redundant task and check pid running --- deployment/README.md | 9 +++--- deployment/auto-deploy-eventmesh-dashboard.sh | 30 ++++++++++++------- .../src/main/resources/logback.xml | 4 +-- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/deployment/README.md b/deployment/README.md index f1bd7471..0a642de8 100644 --- a/deployment/README.md +++ b/deployment/README.md @@ -5,15 +5,14 @@ ``` cd ~/service git clone -b dev https://github.com/apache/eventmesh-dashboard.git -cd eventmesh-dashboard -chmod +x deployment/auto-deploy-eventmesh-dashboard.sh +cd eventmesh-dashboard/deployment/ ``` Edit credentials: ``` -cp deployment/.env.example deployment/.env -vim deployment/.env +cp .env.example .env +vim .env ``` Add task to crontab: @@ -23,5 +22,5 @@ crontab -e ``` ``` -0 * * * * ~/service/eventmesh-dashboard/deployment/auto-deploy-eventmesh-dashboard.sh +0 * * * * bash ~/service/eventmesh-dashboard/deployment/auto-deploy-eventmesh-dashboard.sh ``` \ No newline at end of file diff --git a/deployment/auto-deploy-eventmesh-dashboard.sh b/deployment/auto-deploy-eventmesh-dashboard.sh index 62d40a75..8af598d6 100644 --- a/deployment/auto-deploy-eventmesh-dashboard.sh +++ b/deployment/auto-deploy-eventmesh-dashboard.sh @@ -33,6 +33,16 @@ JAR_FILE_PATH=~/service/eventmesh-dashboard/eventmesh-dashboard-console/target/e ENV_FILE=~/service/eventmesh-dashboard/deployment/.env source $ENV_FILE +# Function to check if a process with given PID is running +is_process_running() { + local pid=$1 + if ps -p $pid > /dev/null; then + return 0 + else + return 1 + fi +} + # Update the git repository cd $REPO_PATH git fetch origin dev @@ -46,10 +56,10 @@ if [ $LOCAL != $REMOTE ]; then # Log the event echo "$(date +"%Y-%m-%d %H:%M:%S") - change detected." >> $AUTO_DEPLOY_LOG - # Terminate the old process + # Terminate the old process if it's running if [ -s $PID_LOG ]; then PID=$(cat $PID_LOG) - if [ -n "$PID" ]; then + if is_process_running $PID; then kill $PID # Log the event echo "$(date +"%Y-%m-%d %H:%M:%S") - kill running application." >> $AUTO_DEPLOY_LOG @@ -57,7 +67,7 @@ if [ $LOCAL != $REMOTE ]; then fi # Compile and package the Jar file - mvn clean package -DskipTests + mvn clean package -DskipTests -Dcheckstyle.skip=true # Start the springboot application and record the process id to pid.log file nohup java -DDB_ADDRESS=$DB_ADDRESS -DDB_USERNAME=$DB_USERNAME -DDB_PASSWORD=$DB_PASSWORD -jar $JAR_FILE_PATH > /dev/null 2>&1 & @@ -71,18 +81,18 @@ else # Log the event echo "$(date +"%Y-%m-%d %H:%M:%S") - no change detected." >> $AUTO_DEPLOY_LOG - 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, compile and package the Jar file - mvn clean package -DskipTests + if [ ! -s $PID_LOG ] || ! is_process_running $(cat $PID_LOG); then + # If the pid.log file does not exist or the process is not running, compile and package the Jar file + mvn clean package -DskipTests -Dcheckstyle.skip=true # Start the springboot application and record the process id to pid.log file nohup java -DDB_ADDRESS=$DB_ADDRESS -DDB_USERNAME=$DB_USERNAME -DDB_PASSWORD=$DB_PASSWORD -jar $JAR_FILE_PATH > /dev/null 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 + echo "$(date +"%Y-%m-%d %H:%M:%S") - no pid.log file or process not running, start application." >> $AUTO_DEPLOY_LOG + else + # If the pid.log file exists and the process is running, no action is performed + echo "$(date +"%Y-%m-%d %H:%M:%S") - application running, no operation performed." >> $AUTO_DEPLOY_LOG fi fi diff --git a/eventmesh-dashboard-console/src/main/resources/logback.xml b/eventmesh-dashboard-console/src/main/resources/logback.xml index 57d00889..ae23589f 100644 --- a/eventmesh-dashboard-console/src/main/resources/logback.xml +++ b/eventmesh-dashboard-console/src/main/resources/logback.xml @@ -19,7 +19,7 @@ - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %magenta(%-5level) %green(%logger{60}) - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %magenta(%-5level) %green(%logger{60}):%blue(%line) - %msg%n @@ -32,7 +32,7 @@ 10 - %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{60} - %msg%n + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{60}:%line - %msg%n UTF-8