Support graceful shutdowns of qbittorrent
This commit is contained in:
parent
0981380ec1
commit
8afa7bcab8
@ -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
|
||||
@ -146,7 +155,9 @@ if [ -e /proc/$qbittorrentpid ]; then
|
||||
if [[ ! "${HEALTH_CHECK_SILENT}" == "1" || ! "${HEALTH_CHECK_SILENT}" == "true" || ! "${HEALTH_CHECK_SILENT}" == "yes" ]]; 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'
|
||||
|
Loading…
x
Reference in New Issue
Block a user