From cb4a7fe6dfbabe9fddf4aa221bf0e20bced14b17 Mon Sep 17 00:00:00 2001 From: Alireza Ahmadi Date: Sun, 7 Jul 2024 23:37:03 +0200 Subject: [PATCH] reload sing-box instead of restart --- core/runSingbox.sh | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/core/runSingbox.sh b/core/runSingbox.sh index 21941ec..78cb32f 100755 --- a/core/runSingbox.sh +++ b/core/runSingbox.sh @@ -20,7 +20,17 @@ terminateSingbox() fi } +reloadSingbox() +{ + if kill -0 $tokill > /dev/null 2>&1; then + kill -HUP $tokill + else + runSingbox + fi +} + trap terminateSingbox SIGINT SIGTERM SIGKILL +trap reloadSingbox SIGHUP runSingbox @@ -32,13 +42,12 @@ do echo "Signal received: $signal" # Remove singnal file rm -f signal >> /dev/null 2>&1 - case ${signal} in + case ${signal} in "stop") terminateSingbox ;; "restart") - terminateSingbox - runSingbox + reloadSingbox ;; esac fi @@ -47,7 +56,7 @@ do if ! kill -0 $tokill > /dev/null 2>&1; then if [ "$signal" != "stop" ]; then echo "Sing-Box with PID $tokill crashed. Breaking the loop..." - break + exit 1 fi fi done \ No newline at end of file