[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
diff --git a/deployment/README.md b/deployment/README.md
index f1bd747..0a642de 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 @@
```
```
-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 62d40a7..8af598d 100644
--- a/deployment/auto-deploy-eventmesh-dashboard.sh
+++ b/deployment/auto-deploy-eventmesh-dashboard.sh
@@ -33,6 +33,16 @@
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 @@
# 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 @@
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 @@
# 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 57d0088..ae23589 100644
--- a/eventmesh-dashboard-console/src/main/resources/logback.xml
+++ b/eventmesh-dashboard-console/src/main/resources/logback.xml
@@ -19,7 +19,7 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder charset="UTF-8">
- <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %magenta(%-5level) %green(%logger{60}) - %msg%n</pattern>
+ <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %magenta(%-5level) %green(%logger{60}):%blue(%line) - %msg%n</pattern>
</encoder>
</appender>
@@ -32,7 +32,7 @@
<MaxHistory>10</MaxHistory>
</rollingPolicy>
<encoder>
- <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{60} - %msg%n</pattern>
+ <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{60}:%line - %msg%n</pattern>
<charset class="java.nio.charset.Charset">UTF-8</charset>
</encoder>
</appender>