From cc439d882f88a86294e6f67c4618a1755278e72d Mon Sep 17 00:00:00 2001 From: binhex Date: Sun, 15 Sep 2019 22:11:45 +0100 Subject: [PATCH] check port is closed before restart --- run/nobody/rtorrent.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/run/nobody/rtorrent.sh b/run/nobody/rtorrent.sh index d6b5827..3c2a5f1 100644 --- a/run/nobody/rtorrent.sh +++ b/run/nobody/rtorrent.sh @@ -9,13 +9,17 @@ if [[ "${rtorrent_running}" == "true" ]]; then # SIGTERM used here as SIGINT does not kill the process pkill -SIGTERM "tmux\: server" - # make sure 'rtorrent main' process DOESNT exist before re-starting - while pgrep -x "rtorrent main" &> /dev/null - do - - sleep 0.5s + echo "[info] Waiting until 'rtorrent main' process has exited..." + while pgrep -x "rtorrent main" &> /dev/null; do + sleep 0.1s + done + echo "[info] Process 'rtorrent main' exited" + echo "[info] Waiting for rtorrent port 5000 to not be in 'listen' state..." + while [[ $(netstat -lnt | awk '$6 == "LISTEN" && $4 ~ ".5000"') != "" ]]; do + sleep 0.1 done + echo "[info] Port 5000 not listening" fi