More better error handling!
This commit is contained in:
parent
a5e9215d92
commit
e8f4c77ed7
|
@ -12,7 +12,7 @@ COPY ./crontab /etc/cron.d/certbot
|
||||||
RUN crontab /etc/cron.d/certbot
|
RUN crontab /etc/cron.d/certbot
|
||||||
|
|
||||||
COPY ./scripts/ /scripts
|
COPY ./scripts/ /scripts
|
||||||
RUN chmod +x /scripts/run_certbot.sh
|
RUN chmod +x /scripts/*.sh
|
||||||
|
|
||||||
ENTRYPOINT []
|
ENTRYPOINT []
|
||||||
CMD ["/bin/bash", "/scripts/entrypoint.sh"]
|
CMD ["/bin/bash", "/scripts/entrypoint.sh"]
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
#!/bin/bash
|
#!/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
|
||||||
|
|
|
@ -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() {
|
get_certificate() {
|
||||||
# Gets the certificate for the domain(s) CERT_DOMAINS (a comma separated list)
|
# Gets the certificate for the domain(s) CERT_DOMAINS (a comma separated list)
|
||||||
|
@ -15,16 +30,19 @@ get_certificate() {
|
||||||
ec=$?
|
ec=$?
|
||||||
echo "certbot exit code $ec"
|
echo "certbot exit code $ec"
|
||||||
if [ $ec -eq 0 ]; then
|
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
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exit_code=0
|
||||||
set -x
|
set -x
|
||||||
for d in $DOMAINS
|
for d in $DOMAINS; do
|
||||||
do
|
CERT_DOMAINS=$d
|
||||||
CERT_DOMAINS=$d
|
if ! get_certificate; then
|
||||||
get_certificate
|
exit_code=1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
exit $exit_code
|
||||||
|
|
Loading…
Reference in New Issue