From d80659ca411950764551e22f2812a9c1dda29125 Mon Sep 17 00:00:00 2001 From: lanyuanxiaoyao Date: Thu, 19 Dec 2024 17:19:28 +0800 Subject: [PATCH] =?UTF-8?q?feat(web):=20=E6=B7=BB=E5=8A=A0=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=90=AF=E5=8A=A8=E5=92=8C=E5=81=9C=E6=AD=A2=E8=84=9A?= =?UTF-8?q?=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 start.sh 脚本,使用 nohup 启动应用并将输出重定向到 run.log - 新增 stop.sh 脚本,实现应用的平滑停止 --- gringotts-web/bin/start.sh | 2 +- gringotts-web/bin/stop.sh | 40 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100755 gringotts-web/bin/stop.sh diff --git a/gringotts-web/bin/start.sh b/gringotts-web/bin/start.sh index e4b4c4f..593b84a 100755 --- a/gringotts-web/bin/start.sh +++ b/gringotts-web/bin/start.sh @@ -1,2 +1,2 @@ export JASYPT_ENCRYPTOR_PASSWORD='r#(R,P"Dp^A47>WSn:Wn].gs/+"v:q_Q*An~zF*g-@j@jtSTv5H/,S-3:R?r9R}.' -/home/iap/gringotts/jdk/jdk-11.0.25+9/bin/java -jar /home/iap/gringotts/gringotts-web-1.0.0-SNAPSHOT.jar --spring.profiles.active=build \ No newline at end of file +nohup /home/iap/gringotts/jdk/jdk-11.0.25+9/bin/java -jar /home/iap/gringotts/gringotts-web-1.0.0-SNAPSHOT.jar --spring.profiles.active=build > run.log 2>&1 & \ No newline at end of file diff --git a/gringotts-web/bin/stop.sh b/gringotts-web/bin/stop.sh new file mode 100755 index 0000000..d390d76 --- /dev/null +++ b/gringotts-web/bin/stop.sh @@ -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 \ No newline at end of file