Fix cron.

This commit is contained in:
redxef 2021-03-15 20:22:21 +01:00
parent 5c1da5bfa5
commit 9efef52563
7 changed files with 45 additions and 20 deletions

View file

@ -1,11 +1,16 @@
FROM alpine:latest FROM alpine:latest
RUN apk update && apk upgrade RUN apk update && apk upgrade \
RUN apk add curl certbot openssl && 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 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"] ENTRYPOINT [ "/bin/sh", "-c" ]
CMD [] CMD [ "duckdns; certbot-duckdns; start-certbot-duckdns.sh" ]

View file

@ -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'

View file

@ -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

3
etc/periodic/12h/certbot Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
sleep $RANDOM && exec certbot-duckdns

3
etc/periodic/5min/duckdns Executable file
View file

@ -0,0 +1,3 @@
#!/usr/bin/env sh
exec duckdns

View file

@ -21,5 +21,5 @@ under the following locations respectively:
## ENV Variables ## ENV Variables
- DUCKDNS_DOMAIN: The domain to update, ex: DUCKDNS_DOMAIN=redxef for redxef.duckdns.org - 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 - LE_EMAIL: Your email for certificate related notifications

View file

@ -1,11 +1,31 @@
#!/usr/bin/env sh #!/usr/bin/env sh
dhparamfile='/etc/letsencrypt/ssl-dhparams.pem' pids=""
ssl_includefile='/etc/letsencrypt/options-ssl-nginx.conf'
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" 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