diff options
Diffstat (limited to 'container')
| -rw-r--r-- | container/cron.py | 42 | ||||
| -rw-r--r-- | container/entrypoint | 13 |
2 files changed, 55 insertions, 0 deletions
diff --git a/container/cron.py b/container/cron.py new file mode 100644 index 0000000..47aeaa9 --- /dev/null +++ b/container/cron.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python +import os +import sys +import datetime +import subprocess +import time + +SLEEPY_TIME = datetime.timedelta(hours=1) +SLEEPY_BATCH = datetime.timedelta(minutes=10) +LOGFILE = "/fietsboek/fietscron.log" + +pid = os.fork() +if pid > 0: + sys.exit(0) + +os.setsid() + +pid = os.fork() +if pid > 0: + sys.exit(0) + + +def run_fietscron(): + with open(LOGFILE, "wb") as stdout: + subprocess.run( + ["/usr/local/bin/fietscron", "-c", "/fietsboek/fietsboek.ini"], + stdout=stdout, + stderr=subprocess.STDOUT, + ) + + +def wait(start): + wanted_time = start + SLEEPY_TIME + while (now := datetime.datetime.now(tz=datetime.UTC)) < wanted_time: + to_sleep = min(wanted_time - now, SLEEPY_BATCH) + time.sleep(to_sleep.total_seconds()) + + +while True: + start = datetime.datetime.now(tz=datetime.UTC) + run_fietscron() + wait(start) diff --git a/container/entrypoint b/container/entrypoint index c7f3b2d..514252c 100644 --- a/container/entrypoint +++ b/container/entrypoint @@ -48,6 +48,16 @@ if [[ ! -f "$CONFIG" ]] ; then sed -i '/^email\.password =/c email.password = '"$EMAIL_PASSWORD" "$CONFIG" fi + if [[ -v OVERPASS_URL ]] ; then + sed -i '/^\[app:main\]/a overpass.url = '"$OVERPASS_URL" "$CONFIG" + fi + if [[ -v OVERPASS_BASIC_AUTH_USERNAME ]] ; then + sed -i '/^\[app:main\]/a overpass.basic_auth.username = '"$OVERPASS_BASIC_AUTH_USERNAME" "$CONFIG" + fi + if [[ -v OVERPASS_BASIC_AUTH_PASSWORD ]] ; then + sed -i '/^\[app:main\]/a overpass.basic_auth.password = '"$OVERPASS_BASIC_AUTH_PASSWORD" "$CONFIG" + fi + if [[ -v LOGLEVEL ]] ; then # We are only changing the fietsboek log level here, as SQLAlchemy # produces a lot of noise. @@ -59,4 +69,7 @@ fi # the first time (cd /package && fietsupdate update -fc "$CONFIG") +# Start a cronjob for fietscron in the background +/usr/bin/cron.py + exec "$@" |
