Merge pull request #87 from DyonR/dev

Graceful shutdown, iptables -V placement, should fix #62, fix HEALTH_CHECK_SILENT
This commit is contained in:
DyonR 2022-01-09 00:35:25 +01:00 committed by GitHub
commit e9c8c2acd0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 21 deletions

View File

@ -10,8 +10,8 @@ RUN mkdir -p /downloads /config/qBittorrent /etc/openvpn /etc/qbittorrent
# Install boost
RUN apt update \
&& apt -y upgrade \
&& apt -y install --no-install-recommends \
&& apt upgrade -y \
&& apt install -y --no-install-recommends \
curl \
ca-certificates \
g++ \
@ -31,7 +31,7 @@ RUN apt update \
g++ \
libxml2-utils \
&& apt-get clean \
&& apt -y autoremove \
&& apt --purge autoremove -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
@ -58,7 +58,7 @@ RUN apt update \
jq \
unzip \
&& apt-get clean \
&& apt autoremove -y \
&& apt --purge autoremove -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
@ -82,7 +82,7 @@ RUN apt update \
curl \
jq \
&& apt-get clean \
&& apt autoremove -y \
&& apt --purge autoremove -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
@ -116,7 +116,7 @@ RUN apt update \
jq \
libssl-dev \
&& apt-get clean \
&& apt autoremove -y \
&& apt --purge autoremove -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
@ -158,7 +158,7 @@ RUN apt update \
qttools5-dev \
zlib1g-dev \
&& apt-get clean \
&& apt autoremove -y \
&& apt --purge autoremove -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
@ -186,14 +186,14 @@ RUN echo "deb http://deb.debian.org/debian/ unstable main" > /etc/apt/sources.li
procps \
wireguard-tools \
&& apt-get clean \
&& apt autoremove -y \
&& apt --purge autoremove -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \
/var/tmp/*
# Install (un)compressing tools like unrar, 7z, unzip and zip
RUN echo "deb http://deb.debian.org/debian/ buster non-free" > /etc/apt/sources.list.d/non-free-unrar.list \
RUN echo "deb http://deb.debian.org/debian/ bullseye non-free" > /etc/apt/sources.list.d/non-free-unrar.list \
&& printf 'Package: *\nPin: release a=non-free\nPin-Priority: 150\n' > /etc/apt/preferences.d/limit-non-free \
&& apt update \
&& apt -y upgrade \
@ -203,7 +203,7 @@ RUN echo "deb http://deb.debian.org/debian/ buster non-free" > /etc/apt/sources.
unzip \
zip \
&& apt-get clean \
&& apt -y autoremove \
&& apt --purge autoremove -y \
&& rm -rf \
/var/lib/apt/lists/* \
/tmp/* \

View File

@ -22,17 +22,15 @@ else
fi
export LEGACY_IPTABLES=$(echo "${LEGACY_IPTABLES,,}")
iptables_version=$(iptables -V)
echo "[INFO] The container is currently running ${iptables_version}." | ts '%Y-%m-%d %H:%M:%.S'
echo "[INFO] LEGACY_IPTABLES is set to '${LEGACY_IPTABLES}'" | ts '%Y-%m-%d %H:%M:%.S'
if [[ $LEGACY_IPTABLES == "1" || $LEGACY_IPTABLES == "true" || $LEGACY_IPTABLES == "yes" ]]; then
echo "[INFO] Setting iptables to iptables (legacy)" | ts '%Y-%m-%d %H:%M:%.S'
update-alternatives --set iptables /usr/sbin/iptables-legacy
iptables_version=$(iptables -V)
echo "[INFO] The container is now running ${iptables_version}." | ts '%Y-%m-%d %H:%M:%.S'
else
echo "[INFO] Not making any changes to iptables version" | ts '%Y-%m-%d %H:%M:%.S'
fi
iptables_version=$(iptables -V)
echo "[INFO] The container is currently running ${iptables_version}." | ts '%Y-%m-%d %H:%M:%.S'
if [[ $VPN_ENABLED == "1" || $VPN_ENABLED == "true" || $VPN_ENABLED == "yes" ]]; then
# Check if VPN_TYPE is set.

View File

@ -7,7 +7,7 @@ fi
chown -R ${PUID}:${PGID} /config/qBittorrent
# Set the rights on the /downloads folder
chown -R ${PUID}:${PGID} /downloads
find /downloads -not -user ${PUID} -execdir chown ${PUID}:${PGID} {} \+
# Check if qBittorrent.conf exists, if not, copy the template over
if [ ! -e /config/qBittorrent/config/qBittorrent.conf ]; then
@ -100,13 +100,22 @@ echo "[INFO] Starting qBittorrent daemon..." | ts '%Y-%m-%d %H:%M:%.S'
/bin/bash /etc/qbittorrent/qbittorrent.init start &
chmod -R 755 /config/qBittorrent
# Wait a second for it to start up and get the process id
sleep 1
qbittorrentpid=$(pgrep -o -x qbittorrent-nox)
echo "[INFO] qBittorrent PID: $qbittorrentpid" | ts '%Y-%m-%d %H:%M:%.S'
# wait for the qbittorrent.init script to finish and grab the qbittorrent pid
# from the file created by the start script
wait $!
qbittorrentpid=$(cat /var/run/qbittorrent.pid)
# If the process exists, make sure that the log file has the proper rights and start the health check
if [ -e /proc/$qbittorrentpid ]; then
echo "[INFO] qBittorrent PID: $qbittorrentpid" | ts '%Y-%m-%d %H:%M:%.S'
# trap the TERM signal for propagation and graceful shutdowns
handle_term() {
echo "[INFO] Received SIGTERM, stopping..." | ts '%Y-%m-%d %H:%M:%.S'
/bin/bash /etc/qbittorrent/qbittorrent.init stop
exit $?
}
trap handle_term SIGTERM
if [[ -e /config/qBittorrent/data/logs/qbittorrent.log ]]; then
chmod 775 /config/qBittorrent/data/logs/qbittorrent.log
fi
@ -143,10 +152,12 @@ if [ -e /proc/$qbittorrentpid ]; then
echo "[ERROR] Network is down, exiting this Docker" | ts '%Y-%m-%d %H:%M:%.S'
exit 1
fi
if [[ ! "${HEALTH_CHECK_SILENT}" == "1" || ! "${HEALTH_CHECK_SILENT}" == "true" || ! "${HEALTH_CHECK_SILENT}" == "yes" ]]; then
if [ "${HEALTH_CHECK_SILENT}" == "0" ] || [ "${HEALTH_CHECK_SILENT}" == "false" ] || [ "${HEALTH_CHECK_SILENT}" == "no" ]; then
echo "[INFO] Network is up" | ts '%Y-%m-%d %H:%M:%.S'
fi
sleep ${INTERVAL}
sleep ${INTERVAL} &
# combine sleep background with wait so that the TERM trap above works
wait $!
done
else
echo "[ERROR] qBittorrent failed to start!" | ts '%Y-%m-%d %H:%M:%.S'