Skip to content

Commit

Permalink
Exclude redundant task and check pid running
Browse files Browse the repository at this point in the history
  • Loading branch information
Pil0tXia committed Mar 31, 2024
1 parent 3ae4e3c commit 4215ec7
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions deployment/auto-deploy-eventmesh-dashboard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,18 +56,18 @@ 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
fi
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 &
Expand All @@ -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

0 comments on commit 4215ec7

Please sign in to comment.