diff --git a/docker/Dockerfile.BackgroundJob b/docker/Dockerfile.BackgroundJob index 7497975..c8b6186 100644 --- a/docker/Dockerfile.BackgroundJob +++ b/docker/Dockerfile.BackgroundJob @@ -83,7 +83,7 @@ ARG S6_VERSION=v2.2.0.3 ENV FLASK_APP=/app/powerdnsadmin/__init__.py \ USER=pda -RUN apk add --no-cache mariadb-connector-c postgresql-client py3-gunicorn py3-psycopg2 xmlsec tzdata libcap && \ +RUN apk add --no-cache mariadb-connector-c postgresql-client py3-gunicorn py3-psycopg2 xmlsec tzdata libcap apk-cron && \ addgroup -S ${USER} && \ adduser -S -D -G ${USER} ${USER} && \ mkdir /data && \ @@ -99,12 +99,27 @@ COPY ./docker/entrypoint.sh /usr/bin/ WORKDIR /app RUN chown ${USER}:${USER} ./configs /app && \ cat ./powerdnsadmin/default_config.py ./configs/docker_config.py > ./powerdnsadmin/docker_config.py + # Add s6 overlay, so we can manage multiple processes ADD https://github.com/just-containers/s6-overlay/releases/download/$S6_VERSION/s6-overlay-amd64-installer /tmp/ RUN chmod +x /tmp/s6-overlay-amd64-installer && /tmp/s6-overlay-amd64-installer / -RUN mkdir /etc/services.d/gunicorn && echo $'#!/usr/bin/execlineb -P\nwith-contenv\n' > /etc/services.d/gunicorn/run && echo "s6-setuidgid $USER" >> /etc/services.d/gunicorn/run && echo $'\n/usr/bin/entrypoint.sh gunicorn powerdnsadmin:create_app()' >> /etc/services.d/gunicorn/run && chmod +x /etc/services.d/gunicorn/run + +# Create service script for gunicorn +RUN mkdir /etc/services.d/gunicorn && \ + echo $'#!/usr/bin/execlineb -P\nwith-contenv\n' > /etc/services.d/gunicorn/run && \ + echo "s6-setuidgid $USER" >> /etc/services.d/gunicorn/run && \ + echo $'\n/usr/bin/entrypoint.sh gunicorn powerdnsadmin:create_app()' >> /etc/services.d/gunicorn/run && \ + chmod +x /etc/services.d/gunicorn/run + +# Create service script for cron +RUN mkdir /etc/services.d/cron && \ + echo $'#!/usr/bin/execlineb -P\ncrond -f\n' > /etc/services.d/cron/run && \ + chmod +x /etc/services.d/cron/run + +# Add crontab entries +RUN echo "*/5 * * * * python3 /app/update_zones.py" >> /etc/crontabs/$USER && \ + echo "*/5 * * * * python3 /app/update_accounts.py" >> /etc/crontabs/$USER EXPOSE 80/tcp -#USER ${USER} HEALTHCHECK CMD ["wget","--output-document=-","--quiet","--tries=1","http://127.0.0.1/"] ENTRYPOINT ["/init"] diff --git a/update_accounts.py b/update_accounts.py index 0578ce0..4c5f04e 100644 --- a/update_accounts.py +++ b/update_accounts.py @@ -25,7 +25,9 @@ with app.app_context(): ### Check if bg_domain_updates is set to true if not status: - app.logger.error('Please turn on "bg_domain_updates" setting to run this job.') - sys.exit(1) + app.logger.debug('"bg_domain_updates" is disabled, exiting') + sys.exit(0) + ### Start the update process + app.logger.info('Update accounts from nameserver API') Account().update() diff --git a/update_zones.py b/update_zones.py index 5da542f..79fc19a 100644 --- a/update_zones.py +++ b/update_zones.py @@ -16,7 +16,6 @@ import logging from powerdnsadmin import create_app from powerdnsadmin.models.domain import Domain from powerdnsadmin.models.setting import Setting - app = create_app() app.logger.setLevel(logging.INFO) @@ -25,8 +24,8 @@ with app.app_context(): ### Check if bg_domain_updates is set to true if not status: - app.logger.error('Please turn on "bg_domain_updates" setting to run this job.') - sys.exit(1) + app.logger.debug('"bg_domain_updates" is disabled, exiting') + sys.exit(0) ### Start the update process app.logger.info('Update domains from nameserver API')