mirror of
https://github.com/bunkerity/bunkerized-nginx
synced 2023-12-13 21:30:18 +01:00
55 lines
No EOL
1.5 KiB
Bash
Executable file
55 lines
No EOL
1.5 KiB
Bash
Executable file
#!/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 |