From 9efef52563507b27005a33824b4f8f0e5f95cb0a Mon Sep 17 00:00:00 2001 From: redxef Date: Mon, 15 Mar 2021 20:22:21 +0100 Subject: [PATCH] Fix cron. --- Dockerfile | 17 +++++++++++------ etc/cron.d/certbot | 3 --- etc/cron.d/duckdns | 3 --- etc/periodic/12h/certbot | 3 +++ etc/periodic/5min/duckdns | 3 +++ readme.md | 2 +- start-certbot-duckdns.sh | 34 +++++++++++++++++++++++++++------- 7 files changed, 45 insertions(+), 20 deletions(-) delete mode 100644 etc/cron.d/certbot delete mode 100644 etc/cron.d/duckdns create mode 100755 etc/periodic/12h/certbot create mode 100755 etc/periodic/5min/duckdns diff --git a/Dockerfile b/Dockerfile index 02f0a26..27f99c5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,16 @@ FROM alpine:latest -RUN apk update && apk upgrade -RUN apk add curl certbot openssl +RUN apk update && apk upgrade \ + && apk add \ + curl \ + certbot \ + openssl + +RUN mkdir -p /etc/periodic/12h \ + && mkdir -p /etc/periodic/5min -RUN mkdir /etc/cron.d COPY certbot-* duckdns start-certbot-duckdns.sh /usr/local/bin/ -COPY etc/cron.d/* /etc/cron.d/ +COPY etc/periodic/ /etc/periodic/ -ENTRYPOINT ["start-certbot-duckdns.sh"] -CMD [] +ENTRYPOINT [ "/bin/sh", "-c" ] +CMD [ "duckdns; certbot-duckdns; start-certbot-duckdns.sh" ] diff --git a/etc/cron.d/certbot b/etc/cron.d/certbot deleted file mode 100644 index 726d111..0000000 --- a/etc/cron.d/certbot +++ /dev/null @@ -1,3 +0,0 @@ -SHELL=/bin/sh -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -* */12 * * * root sh -c 'sleep \$RANDOM && certbot-duckdns' diff --git a/etc/cron.d/duckdns b/etc/cron.d/duckdns deleted file mode 100644 index 1ef2cea..0000000 --- a/etc/cron.d/duckdns +++ /dev/null @@ -1,3 +0,0 @@ -SHELL=/bin/sh -PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin -*/5 * * * * root duckdns >/dev/null 2>&1 diff --git a/etc/periodic/12h/certbot b/etc/periodic/12h/certbot new file mode 100755 index 0000000..31c37f4 --- /dev/null +++ b/etc/periodic/12h/certbot @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +sleep $RANDOM && exec certbot-duckdns diff --git a/etc/periodic/5min/duckdns b/etc/periodic/5min/duckdns new file mode 100755 index 0000000..f2fbe2d --- /dev/null +++ b/etc/periodic/5min/duckdns @@ -0,0 +1,3 @@ +#!/usr/bin/env sh + +exec duckdns diff --git a/readme.md b/readme.md index 0eeac96..de45f31 100644 --- a/readme.md +++ b/readme.md @@ -21,5 +21,5 @@ under the following locations respectively: ## ENV Variables - DUCKDNS_DOMAIN: The domain to update, ex: DUCKDNS_DOMAIN=redxef for redxef.duckdns.org -- DUCKDNS_TOKEN: Your duckdns api tokne +- DUCKDNS_TOKEN: Your duckdns api token - LE_EMAIL: Your email for certificate related notifications diff --git a/start-certbot-duckdns.sh b/start-certbot-duckdns.sh index a4a0de9..6b12191 100755 --- a/start-certbot-duckdns.sh +++ b/start-certbot-duckdns.sh @@ -1,11 +1,31 @@ #!/usr/bin/env sh -dhparamfile='/etc/letsencrypt/ssl-dhparams.pem' -ssl_includefile='/etc/letsencrypt/options-ssl-nginx.conf' +pids="" + +run_prog() { + "$@" & + pids="$! $pids" +} + +trap_sig() { + printf '%s' "$pids" | while IFS= read -r pid; do + echo "pid=$pid" + kill -s $1 $pid + done +} + +trap 'trap_sig TERM' SIGTERM + +# echo "Updating duckdns record" +# duckdns + +# echo "Acquiering letsencrypt certificates" +# certbot-duckdns "$@" -echo "Updating duckdns record" -duckdns -echo "Acquiering letsencrypt certificates" -certbot-duckdns "$@" echo "Starting crond" -exec crond -f +printf '*/5\t*\t*\t*\t*\trun-parts /etc/periodic/5min\n' >> /etc/crontabs/root +printf '*\t*/12\t*\t*\t*\trun-parts /etc/periodic/12h\n' >> /etc/crontabs/root +crontab -l + +run_prog crond -l 0 -fc /etc/crontabs/ +wait $pids