Skip to content
This repository has been archived by the owner on Jun 28, 2023. It is now read-only.

Commit

Permalink
check port is closed before restart
Browse files Browse the repository at this point in the history
  • Loading branch information
binhex committed Sep 15, 2019
1 parent 5afcabe commit cc439d8
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions run/nobody/rtorrent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit cc439d8

Please sign in to comment.