11#! /usr/bin/env sh
2- # Minigrid Server installer for version 0.0.3
2+ # Minigrid Server installer for version 0.0.4
33set -e
44
55# Do you have docker installed?
@@ -108,8 +108,8 @@ $SUDO openssl dhparam -out /etc/letsencrypt/live/$LETSENCRYPT_DIR/dhparam.pem 20
108108printf " ========================================\n"
109109printf " Downloading configuration files \n"
110110printf " ========================================\n"
111- $CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.0.3 /prod/docker-compose.yml > docker-compose.yml
112- $CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.0.3 /prod/nginx.conf > nginx.conf
111+ $CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.0.4 /prod/docker-compose.yml > docker-compose.yml
112+ $CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.0.4 /prod/nginx.conf > nginx.conf
113113
114114sed -i s/www.example.com/$LETSENCRYPT_DIR /g docker-compose.yml
115115sed -i s/www.example.com/$LETSENCRYPT_DIR /g nginx.conf
@@ -133,7 +133,19 @@ printf "========================================\n"
133133printf " Adding twice-daily cron job to renew \n"
134134printf " SSL certificate. \n"
135135printf " ========================================\n"
136- CRON_CMD=" mkdir -p /tmp/letsencrypt && docker run -it --rm --name certbot -v /etc/letsencrypt:/etc/letsencrypt:Z -v /var/lib/letsencrypt:/var/lib/letsencrypt:Z -v /tmp/letsencrypt:/tmp/letsencrypt:Z -v /var/log/letsencrypt:/var/log/letsencrypt:Z quay.io/letsencrypt/letsencrypt --renew certonly --webroot -w /tmp/letsencrypt $DOMAIN_ARGS && docker restart $NGINX_CONTAINER_NAME "
137- CRON_JOB=" 07 01,13 * * * $CRON_CMD "
136+ # The --post-hook should just be docker restart $NGINX_CONTAINER_NAME... but
137+ # the container can't run the docker command properly.
138+ # So /tmp/renewed serves as a sentinel
139+ CRON_CMD=" mkdir -p /tmp/letsencrypt && " \
140+ " docker run -it --rm --name certbot" \
141+ " -v /etc/letsencrypt:/etc/letsencrypt:Z" \
142+ " -v /var/lib/letsencrypt:/var/lib/letsencrypt:Z" \
143+ " -v /tmp:/tmp:Z" \
144+ " -v /var/log/letsencrypt:/var/log/letsencrypt:Z" \
145+ " quay.io/letsencrypt/letsencrypt renew --quiet --post-hook 'touch /tmp/renewed' ; " \
146+ " if [ -f /tmp/renewed ] ; then docker restart $NGINX_CONTAINER_NAME ; fi ; " \
147+ " rm -f /tmp/renewed"
148+ # https://certbot.eff.org/#ubuntuxenial-nginx recommends running this twice a day on random minute within the hour
149+ CRON_JOB=" 00 01,13 * * * sleep $( expr $RANDOM \% 59) ; $CRON_CMD "
138150crontab -l | fgrep -i -v " $CRON_CMD " | { cat; echo " $CRON_JOB " ; } | crontab -
139151crontab -l
0 commit comments