diff --git a/scripts/deploy.sh b/scripts/deploy.sh index 93f0524..93e11d5 100644 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -1,13 +1,23 @@ #!/bin/sh # 找到Springboot项目对应的进程id -P_ID=`ps -ef | grep -w demo4bonus-0.0.1 | grep -v "grep" | awk '{print $2}'` +P_ID=$(pgrep -f "demo4bonus-0.0.1") # 如果该项目已经在服务器上启动则kill掉 -echo “原应用程序进程id:$P_ID” -if [ "$P_ID" == "" ]; then - echo "===service process doest not exist" +echo "原应用程序进程id:$P_ID" +if [ -z "$P_ID" ]; then + echo "==Demo service process does not exist" else - kill -9 $P_ID - echo "service killed success" + # 尝试优雅地关闭应用程序 + kill -SIGTERM "$P_ID" + wait "$P_ID" 2>/dev/null + + # 检查进程是否仍在运行 + if ! ps -p "$P_ID" > /dev/null; then + echo "Demo service process was terminated gracefully" + else + # 如果优雅关闭失败,则强制杀死进程 + kill -SIGKILL "$P_ID" + echo "Demo service process was killed forcefully" + fi fi echo "授权"