Ditch `cron` for `bash`

This commit is contained in:
staticfloat@gmail.com 2018-05-01 23:03:42 -07:00
parent 844d521c95
commit b8b50ae5da
4 changed files with 17 additions and 8 deletions

View File

@ -8,7 +8,7 @@ EXPOSE 443
# Do this apt/pip stuff all in one RUN command to avoid creating large
# intermediate layers on non-squashable docker installs
RUN apt update && \
apt install -y cron python python-dev libffi6 libffi-dev libssl-dev curl build-essential && \
apt install -y python python-dev libffi6 libffi-dev libssl-dev curl build-essential && \
curl -L 'https://bootstrap.pypa.io/get-pip.py' | python && \
pip install -U cffi certbot && \
apt remove --purge -y python-dev build-essential libffi-dev libssl-dev curl && \
@ -16,8 +16,7 @@ RUN apt update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Copy in cron job and scripts for certbot
COPY ./crontab /etc/cron.d/certbot
# Copy in scripts for certbot
COPY ./scripts/ /scripts
RUN chmod +x /scripts/*.sh

View File

@ -11,6 +11,9 @@ This repository was originally forked from `@henridwyer`, many thanks to him for
# Changelog
### 0.8
- Ditch cron, it never liked me anway. Just use `sleep` and a `while` loop instead.
### 0.7
- Complete rewrite, build this image on top of the `nginx` image, and run `cron`/`certbot` alongside `nginx` so that we can have nginx configs dynamically enabled as we get SSL certificates.

View File

@ -1 +0,0 @@
0 */12 * * * root sh /scripts/run_certbot.sh

View File

@ -26,7 +26,15 @@ for f in /scripts/startup/*.sh; do
done
echo "Done with startup"
# Run `cron -f &` so that it's a background job owned by bash and then `wait`.
# This allows SIGINT (e.g. CTRL-C) to kill cron gracefully, due to our `trap`.
cron -f &
wait "$NGINX_PID"
# Instead of trying to run `cron` or something like that, just leep and run `certbot`.
while [ true ]; do
# Sleep for 1 week
sleep 604800 &
SLEEP_PID=$!
# re-run certbot
/scripts/run_certbot.sh
# Wait on sleep so that when we get ctrl-c'ed it kills everything due to our trap
wait "$SLEEP_PID"
done