You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
arch-qbittorrentvpn/run/nobody/qbittorrent.sh

92 lines
2.4 KiB

#!/bin/bash
# kill qbittorrent (required due to the fact qbittorrent cannot cope with dynamic changes to port)
if [[ "${qbittorrent_running}" == "true" ]]; then
6 years ago
# 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..."
6 years ago
# SIGTERM used here as SIGINT does not kill the process
pkill -SIGTERM "qbittorrent-nox"
6 years ago
# make sure 'qbittorrent-nox' process DOESNT exist before re-starting
while pgrep -x "qbittorrent-nox" &> /dev/null
do
6 years ago
sleep 0.5s
6 years ago
done
fi
6 years ago
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
6 years ago
# run qBittorrent (daemonized, non-blocking), specifying listening interface and port
/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
6 years ago
# run qBittorrent (daemonized, non-blocking), specifying listening interface
/usr/bin/qbittorrent-nox --daemon --webui-port="${WEBUI_PORT}" --profile=/config --relative-fastresume
fi
# set qbittorrent ip to current vpn ip (used when checking for changes on next run)
qbittorrent_ip="${vpn_ip}"
else
# run tmux attached to qBittorrent (daemonized, non-blocking)
/usr/bin/qbittorrent-nox --daemon --webui-port="${WEBUI_PORT}" --profile=/config --relative-fastresume
fi
# make sure process qbittorrent DOES exist
retry_count=30
while true; do
6 years ago
if ! pgrep -x "qbittorrent-nox" > /dev/null; then
6 years ago
retry_count=$((retry_count-1))
if [ "${retry_count}" -eq "0" ]; then
6 years ago
echo "[warn] Wait for qBittorrent process to start aborted"
break
6 years ago
else
6 years ago
if [[ "${DEBUG}" == "true" ]]; then
echo "[debug] Waiting for qBittorrent process to start..."
fi
6 years ago
sleep 1s
6 years ago
fi
6 years ago
else
6 years ago
echo "[info] qBittorrent process started"
break
6 years ago
fi
done
echo "[info] Waiting for qBittorrent process to start listening on port ${WEBUI_PORT}..."
while [[ $(netstat -lnt | awk "\$6 == \"LISTEN\" && \$4 ~ \".${WEBUI_PORT}\"") == "" ]]; do
6 years ago
sleep 0.1
done
echo "[info] qBittorrent process listening"