feat(web): 添加应用启动和停止脚本
- 修改 start.sh 脚本,使用 nohup 启动应用并将输出重定向到 run.log - 新增 stop.sh 脚本,实现应用的平滑停止
This commit is contained in:
40
gringotts-web/bin/stop.sh
Executable file
40
gringotts-web/bin/stop.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
original_command="$0"
|
||||
application_name="gringotts-web-1.0.0-SNAPSHOT.jar"
|
||||
|
||||
function get_pid() {
|
||||
ID=$(ps ef | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{ print $2 }')
|
||||
if [[ -z "$ID" ]]; then
|
||||
ID=$(ps aux | grep "$application_name" | grep -v grep | grep -v $original_command | awk '{print $2}')
|
||||
if [[ -z "$ID" ]]; then
|
||||
ID=$(/home/iap/gringotts/jdk/jdk-11.0.25+9/bin/jps -lmvV | grep "$application_name" | awk '{print $1}')
|
||||
fi
|
||||
fi
|
||||
echo $ID
|
||||
}
|
||||
|
||||
pid=$(get_pid)
|
||||
|
||||
if [[ -z "$pid" ]]; then
|
||||
echo "Application is already stopped."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Stopping $pid..."
|
||||
kill $pid
|
||||
|
||||
LOOPS=0
|
||||
while (true); do
|
||||
cpid=$(get_pid)
|
||||
if [[ -z "$cpid" ]]; then
|
||||
echo "Oook! cost:$LOOPS"
|
||||
break
|
||||
fi
|
||||
LOOPS=$(($LOOPS+1))
|
||||
if [[ $(($LOOPS%15)) -eq 0 ]]; then
|
||||
echo "Wait timeout, try to force kill $pid..."
|
||||
kill -9 $pid
|
||||
fi
|
||||
sleep 1s
|
||||
done
|
||||
Reference in New Issue
Block a user