Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #81] Reduce the probability of compilation jams and abnormal application exits #82

Merged
merged 3 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions deployment/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
```
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
4 changes: 2 additions & 2 deletions eventmesh-dashboard-console/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand All @@ -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>
Expand Down
Loading