Skip to content

Commit

Permalink
check incoming port using ext site
Browse files Browse the repository at this point in the history
  • Loading branch information
binhex committed Jul 31, 2019
1 parent 9a4cacb commit 9792f4c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions run/nobody/watchdog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ grep -q 'General\\Locale' "${qbittorrent_config}" || sed -i '/\[Preferences\]/a
qbittorrent_port="6881"
qbittorrent_ip="0.0.0.0"

# define sleep period between loops
sleep_period_secs=30

# define sleep period between incoming port checks
sleep_period_incoming_port_secs=1800

# sleep period counter - used to limit number of hits to external website to check incoming port
sleep_period_counter_secs=0

# while loop to check ip and port
while true; do

Expand Down Expand Up @@ -103,15 +112,13 @@ while true; do

if [[ "${qbittorrent_running}" == "true" ]]; then

# run netcat to identify if port still open, use exit code
nc_exitcode=$(/usr/bin/nc -z -w 3 "${vpn_ip}" "${qbittorrent_port}")
if [ "${sleep_period_counter_secs}" -ge "${sleep_period_incoming_port_secs}" ]; then

if [[ "${nc_exitcode}" -ne 0 ]]; then
# run script to check incoming port is accessible
source /home/nobody/checkextport.sh

echo "[info] qBittorrent incoming port closed, marking for reconfigure"

# mark as reconfigure required due to mismatch
port_change="true"
# reset sleep period counter
sleep_period_counter_secs=0

fi

Expand Down Expand Up @@ -196,6 +203,9 @@ while true; do

fi

sleep 30s
# increment sleep period counter - used to limit number of hits to external website to check incoming port
sleep_period_counter_secs=$((sleep_period_counter_secs+"${sleep_period_secs}"))

sleep "${sleep_period_secs}"s

done

0 comments on commit 9792f4c

Please sign in to comment.