From 24933dc3219d484f3616be5e18370cc5610dbf71 Mon Sep 17 00:00:00 2001 From: pan <1029559041@qq.com> Date: Sat, 10 Oct 2020 23:38:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0openresty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shell/killNode | 6 +++--- shell/savePid | 12 +++++++----- shell/updateRisk | 22 ++++++++++++++++------ 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/shell/killNode b/shell/killNode index 3f20bc3..49ad108 100644 --- a/shell/killNode +++ b/shell/killNode @@ -1,13 +1,13 @@ #!/bin/sh #杀死进程 -if [ -e *.log ] +if [ -e pid ] then - pid=`stat *.log|awk 'NR>1{next}{c=$0;gsub(/\D/,"",c);print c}'` + pid=`echo pid` kill -9 $pid if [ $? -eq 0 ] then echo "kill $pid success" - rm -f *.log + rm -f pid fi fi ./run.sh diff --git a/shell/savePid b/shell/savePid index 702a286..420470f 100644 --- a/shell/savePid +++ b/shell/savePid @@ -1,16 +1,18 @@ #!/bin/sh #保存应用进程pid echo "findPort $1" +#重试时间 +second=5s while true do pid=`findPortPid $1` - if [ -z $pid ] + if [ `$pid|wc -l` -eq 0 ] then - echo "pid not found!!!" - sleep 1s + echo "没有找到端口$1的pid,$second后重试" + sleep $second else - echo "pid is $pid" - touch $pid.log && chmod +x $pid.log + echo "端口$1的pid:$pid" + echo $pid>pid break fi done diff --git a/shell/updateRisk b/shell/updateRisk index 7d317f0..e2b9181 100644 --- a/shell/updateRisk +++ b/shell/updateRisk @@ -1,6 +1,8 @@ #!/bin/sh #自动部署脚本 +echo $$>$1.pid + cd /app source riskenv @@ -22,14 +24,22 @@ function run(){ fi } -#检查是否正在部署 -result=`ps -ef|grep 'updateRisk $1'|wc -l` -echo $result -if [ ! -z $result ] +#如果当前存在自动部署进程直接kill掉 +if [ `ls -l *.pid|wc -l` -gt 0 ] then - echo "检测到自动部署$1进程在运行,直接kill掉" - kill -9 $result + for file in *.pid + do + pid=`cat $file` + kill -9 $pid + if [ $? -eq 0 ] + then + echo "成功杀死进程:$pid" + rm -f $file + fi + done fi run $1 +rm -f $1.pid +