Have container shut down if VPN or qbittorrent dies

This commit is contained in:
Greg Pringle 2021-05-15 07:37:58 -06:00
parent 00bce09f7f
commit bf8b282876
2 changed files with 19 additions and 3 deletions

View File

@ -18,7 +18,7 @@ RUN apt-get update \
&& apt-get install -y software-properties-common \ && apt-get install -y software-properties-common \
&& add-apt-repository ppa:qbittorrent-team/qbittorrent-stable \ && add-apt-repository ppa:qbittorrent-team/qbittorrent-stable \
&& apt-get update \ && apt-get update \
&& apt-get install -y jq traceroute qbittorrent-nox openvpn curl moreutils net-tools dos2unix kmod iptables ipcalc unrar \ && apt-get install -y iputils-ping jq traceroute qbittorrent-nox openvpn curl moreutils net-tools dos2unix kmod iptables ipcalc unrar \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# Add configuration and scripts # Add configuration and scripts

View File

@ -84,12 +84,28 @@ if [ -e /proc/$qbpid ]; then
chmod 775 /config/qBittorrent/data/logs/qbittorrent.log chmod 775 /config/qBittorrent/data/logs/qbittorrent.log
if [[ $PFWD == "yes" ]]; then if [[ $PFWD == "yes" ]]; then
echo "[info] PIA Port forwarding configured, calling pia_port_forwarding.sh" echo "[info] PIA Port forwarding configured, calling pia_port_forwarding.sh"
/bin/bash /etc/openvpn/pia_port_forwarding.sh /bin/bash /etc/openvpn/pia_port_forwarding.sh &
else else
echo "[info] PIA Port forwarding not enabled" echo "[info] PIA Port forwarding not enabled"
fi fi
fi fi
sleep infinity while true; do
sleep 60 #check once per minute if VPN is up
ping -I tun0 -c 1 8.8.8.8 > /dev/null && VPNUP=true || VPNUP=false
if [[ $VPNUP == false ]]; then
echo "[crit] VPN down, shutting down docker (turn on auto restart to reconnect)" | ts '%Y-%m-%d %H:%M:%.S'
exit 5
fi
pidof qbittorrent-nox >& /dev/null
if [[ $? -ne 0 ]]; then
sleep 10 #check again after 10 secs.. maybe we were just restarting service to get new port forward
pidof qbittorrent-nox >& /dev/null
if [[ $? -ne 0 ]]; then
echo "[crit] qbittorrent stopped, shutting down docker (turn on auto restart to reconnect)" | ts '%Y-%m-%d %H:%M:%.S'
exit 6
fi
fi
done
else else
echo "qBittorrent failed to start!" echo "qBittorrent failed to start!"
fi fi