bunkerized-nginx/src/scheduler/entrypoint.sh

55 lines
No EOL
1.5 KiB
Bash
Executable file
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
. /usr/share/bunkerweb/helpers/utils.sh
# trap SIGTERM and SIGINT
function trap_exit() {
log "ENTRYPOINT" " " "Catched stop operation"
if [ -f "/var/tmp/bunkerweb/scheduler.pid" ] ; then
log "ENTRYPOINT" " " "Stopping job scheduler ..."
kill -s TERM "$(cat /var/tmp/bunkerweb/scheduler.pid)"
fi
}
trap "trap_exit" TERM INT QUIT
if [ -f /var/tmp/bunkerweb/scheduler.pid ] ; then
rm -f /var/tmp/bunkerweb/scheduler.pid
fi
log "ENTRYPOINT" "" "Starting the job scheduler v$(cat /usr/share/bunkerweb/VERSION) ..."
# setup and check /data folder
/usr/share/bunkerweb/helpers/data.sh "ENTRYPOINT"
if [ "$SWARM_MODE" == "yes" ] ; then
echo "Swarm" > /usr/share/bunkerweb/INTEGRATION
elif [ "$KUBERNETES_MODE" == "yes" ] ; then
echo "Kubernetes" > /usr/share/bunkerweb/INTEGRATION
elif [ "$AUTOCONF_MODE" == "yes" ] ; then
echo "Autoconf" > /usr/share/bunkerweb/INTEGRATION
fi
if ! grep -q "Docker" /usr/share/bunkerweb/INTEGRATION ; then
# Init database
get_env > "/tmp/variables.env"
/usr/share/bunkerweb/gen/save_config.py --variables /tmp/variables.env --init
if [ "$?" -ne 0 ] ; then
log "ENTRYPOINT" "❌" "Scheduler generator failed"
exit 1
fi
fi
# execute jobs
log "ENTRYPOINT" " " "Executing scheduler ..."
/usr/share/bunkerweb/scheduler/main.py &
pid="$!"
wait "$pid"
while [ -f /var/tmp/bunkerweb/scheduler.pid ] ; do
wait "$pid"
done
if [ -f /var/tmp/bunkerweb/scheduler.healthy ] ; then
rm /var/tmp/bunkerweb/scheduler.healthy
fi
log "ENTRYPOINT" " " "Scheduler stopped"
exit 0