From d30264ed08980c37aea66596a74f4862d702ed35 Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Thu, 28 Apr 2022 21:44:32 +0800 Subject: [PATCH] script: force stop smartdns process --- etc/init.d/smartdns | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/etc/init.d/smartdns b/etc/init.d/smartdns index 367af38..c64157b 100644 --- a/etc/init.d/smartdns +++ b/etc/init.d/smartdns @@ -68,11 +68,23 @@ case $1 in echo "Stop smartdns server failed." exit 1; fi - rm -f "$PIDFILE" + LOOP=1 + while true; do + if [ ! -d "/proc/$PID" ]; then + break; + fi + + if [ $LOOP -gt 12 ]; then + kill -9 "$PID" + break; + fi + LOOP=$((LOOP+1)) + sleep .5 + done echo "Stop smartdns server success." ;; restart) - "$0" stop && sleep 1 && "$0" start + "$0" stop && "$0" start ;; status) PID="$(cat "$PIDFILE" 2>/dev/null)"