parent
7029c2fe2e
commit
391f1a2346
@ -1,91 +1,68 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# kill qbittorrent (required due to the fact qbittorrent cannot cope with dynamic changes to port)
|
# change incoming port using the qbittorrent api - note this requires anonymous authentication via webui
|
||||||
|
# option 'Bypass authentication for clients on localhost'
|
||||||
if [[ "${qbittorrent_running}" == "true" ]]; then
|
if [[ "${qbittorrent_running}" == "true" ]]; then
|
||||||
|
|
||||||
# note its not currently possible to change port and/or ip address whilst running, thus the sigterm
|
|
||||||
echo "[info] Sending SIGTERM (-15) to 'qbittorrent-nox' (will terminate qbittorrent) due to port/ip change..."
|
|
||||||
|
|
||||||
# SIGTERM used here as SIGINT does not kill the process
|
|
||||||
pkill -SIGTERM "qbittorrent-nox"
|
|
||||||
|
|
||||||
# make sure 'qbittorrent-nox' process DOESNT exist before re-starting
|
|
||||||
while pgrep -x "qbittorrent-nox" &> /dev/null
|
|
||||||
do
|
|
||||||
|
|
||||||
sleep 0.5s
|
|
||||||
|
|
||||||
done
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "[info] Removing session lock file (if it exists)..."
|
|
||||||
rm -f /config/qBittorrent/data/BT_backup/session.lock
|
|
||||||
|
|
||||||
echo "[info] Attempting to start qBittorrent..."
|
|
||||||
|
|
||||||
if [[ "${VPN_ENABLED}" == "yes" ]]; then
|
|
||||||
|
|
||||||
if [[ "${VPN_PROV}" == "pia" && -n "${VPN_INCOMING_PORT}" ]]; then
|
if [[ "${VPN_PROV}" == "pia" && -n "${VPN_INCOMING_PORT}" ]]; then
|
||||||
|
|
||||||
# run qBittorrent (daemonized, non-blocking), specifying listening interface and port
|
curl -i -X POST -d "json=%7B%22listen_port%22%3A${VPN_INCOMING_PORT}%7D" "http://localhost:${WEBUI_PORT}/command/setPreferences"
|
||||||
/usr/bin/qbittorrent-nox --daemon --webui-port="${WEBUI_PORT}" --profile=/config --relative-fastresume
|
|
||||||
|
|
||||||
# set qbittorrent port to current vpn port (used when checking for changes on next run)
|
|
||||||
qbittorrent_port="${VPN_INCOMING_PORT}"
|
|
||||||
|
|
||||||
else
|
|
||||||
|
|
||||||
# run qBittorrent (daemonized, non-blocking), specifying listening interface
|
|
||||||
/usr/bin/qbittorrent-nox --daemon --webui-port="${WEBUI_PORT}" --profile=/config --relative-fastresume
|
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set qbittorrent ip to current vpn ip (used when checking for changes on next run)
|
|
||||||
qbittorrent_ip="${vpn_ip}"
|
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
||||||
# run tmux attached to qBittorrent (daemonized, non-blocking)
|
echo "[info] Removing session lock file (if it exists)..."
|
||||||
|
rm -f /config/qBittorrent/data/BT_backup/session.lock
|
||||||
|
|
||||||
|
echo "[info] Attempting to start qBittorrent..."
|
||||||
|
|
||||||
|
# run qBittorrent (daemonized, non-blocking) - note qbittorrent requires docker privileged flag
|
||||||
/usr/bin/qbittorrent-nox --daemon --webui-port="${WEBUI_PORT}" --profile=/config --relative-fastresume
|
/usr/bin/qbittorrent-nox --daemon --webui-port="${WEBUI_PORT}" --profile=/config --relative-fastresume
|
||||||
|
|
||||||
fi
|
# make sure process qbittorrent-nox DOES exist
|
||||||
|
retry_count=30
|
||||||
|
while true; do
|
||||||
|
|
||||||
# make sure process qbittorrent DOES exist
|
if ! pgrep -x "qbittorrent-nox" > /dev/null; then
|
||||||
retry_count=30
|
|
||||||
while true; do
|
|
||||||
|
|
||||||
if ! pgrep -x "qbittorrent-nox" > /dev/null; then
|
retry_count=$((retry_count-1))
|
||||||
|
if [ "${retry_count}" -eq "0" ]; then
|
||||||
|
|
||||||
retry_count=$((retry_count-1))
|
echo "[warn] Wait for qBittorrent process to start aborted"
|
||||||
if [ "${retry_count}" -eq "0" ]; then
|
break
|
||||||
|
|
||||||
echo "[warn] Wait for qBittorrent process to start aborted"
|
else
|
||||||
break
|
|
||||||
|
|
||||||
else
|
if [[ "${DEBUG}" == "true" ]]; then
|
||||||
|
echo "[debug] Waiting for qBittorrent process to start..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
sleep 1s
|
||||||
|
|
||||||
if [[ "${DEBUG}" == "true" ]]; then
|
|
||||||
echo "[debug] Waiting for qBittorrent process to start..."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 1s
|
else
|
||||||
|
|
||||||
|
echo "[info] qBittorrent process started"
|
||||||
|
break
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
else
|
done
|
||||||
|
|
||||||
echo "[info] qBittorrent process started"
|
echo "[info] Waiting for qBittorrent process to start listening on port ${WEBUI_PORT}..."
|
||||||
break
|
|
||||||
|
|
||||||
fi
|
while [[ $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".${WEBUI_PORT}\"") == "" ]]; do
|
||||||
|
sleep 0.1
|
||||||
|
done
|
||||||
|
|
||||||
done
|
# change incoming port using the qbittorrent api - note this requires anonymous authentication via webui
|
||||||
|
# option 'Bypass authentication for clients on localhost'
|
||||||
|
if [[ "${VPN_PROV}" == "pia" && -n "${VPN_INCOMING_PORT}" ]]; then
|
||||||
|
|
||||||
echo "[info] Waiting for qBittorrent process to start listening on port ${WEBUI_PORT}..."
|
curl -i -X POST -d "json=%7B%22listen_port%22%3A${VPN_INCOMING_PORT}%7D" "http://localhost:${WEBUI_PORT}/command/setPreferences"
|
||||||
|
|
||||||
while [[ $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".${WEBUI_PORT}\"") == "" ]]; do
|
fi
|
||||||
sleep 0.1
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "[info] qBittorrent process listening"
|
fi
|
||||||
|
Loading…
Reference in new issue