From b1b852d82c70759d8c975f005a81817c6536e4ae Mon Sep 17 00:00:00 2001 From: meeb Date: Fri, 27 Aug 2021 17:13:25 +1000 Subject: [PATCH] add check for stale PID file or old processes to gracefully handle hard container stop/starts, discussed in #144 --- config/root/etc/services.d/gunicorn/run | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/config/root/etc/services.d/gunicorn/run b/config/root/etc/services.d/gunicorn/run index 08f356e8..68a574b6 100755 --- a/config/root/etc/services.d/gunicorn/run +++ b/config/root/etc/services.d/gunicorn/run @@ -5,5 +5,20 @@ umask "$UMASK_SET" cd /app || exit +PIDFILE=/run/app/gunicorn.pid + +if [ -f "${PIDFILE}" ] +then + PID=$(cat $PIDFILE) + echo "Unexpected PID file exists at ${PIDFILE} with PID: ${PID}" + if kill -0 $PID + then + echo "Killing old gunicorn process with PID: ${PID}" + kill -9 $PID + fi + echo "Removing stale PID file: ${PIDFILE}" + rm ${PIDFILE} +fi + exec s6-setuidgid app \ /usr/local/bin/gunicorn -c /app/tubesync/gunicorn.py --capture-output tubesync.wsgi:application