More better error handling!

This commit is contained in:
Elliot Saba 2017-01-19 18:17:56 -08:00
parent a5e9215d92
commit e8f4c77ed7
3 changed files with 32 additions and 11 deletions

View File

@ -12,7 +12,7 @@ COPY ./crontab /etc/cron.d/certbot
RUN crontab /etc/cron.d/certbot
COPY ./scripts/ /scripts
RUN chmod +x /scripts/run_certbot.sh
RUN chmod +x /scripts/*.sh
ENTRYPOINT []
CMD ["/bin/bash", "/scripts/entrypoint.sh"]

View File

@ -1,3 +1,6 @@
#!/bin/bash
/bin/bash /scripts/run_certbot.sh
exec cron -f
trap "exit" INT TERM
trap "kill 0" EXIT
/scripts/run_certbot.sh && cron -f &
wait

View File

@ -1,4 +1,19 @@
echo "Running certbot for domains $DOMAINS"
error() {
(set +x; tput -Tscreen bold
tput -Tscreen setaf 1
echo $*
tput -Tscreen sgr0) >&2
}
if [ -z "$DOMAINS" ]; then
error "DOMAINS environment variable undefined; certbot will do nothing"
exit 1
fi
if [ -z "$EMAIL" ]; then
error "EMAIL environment variable undefined; certbot will do nothing"
exit 1
fi
echo "Running certbot for domains $DOMAINS for user $EMAIL..."
get_certificate() {
# Gets the certificate for the domain(s) CERT_DOMAINS (a comma separated list)
@ -15,16 +30,19 @@ get_certificate() {
ec=$?
echo "certbot exit code $ec"
if [ $ec -eq 0 ]; then
echo "Certificates for $CERT_DOMAINS can be found in /etc/letsencrypt/live/$d"
error "Certificates for $CERT_DOMAINS can be found in /etc/letsencrypt/live/$d"
else
echo "Cerbot failed for $CERT_DOMAINS. Check the logs for details."
error "Cerbot failed for $CERT_DOMAINS. Check the logs for details."
exit 1
fi
}
exit_code=0
set -x
for d in $DOMAINS
do
CERT_DOMAINS=$d
get_certificate
for d in $DOMAINS; do
CERT_DOMAINS=$d
if ! get_certificate; then
exit_code=1
fi
done
exit $exit_code