ansible-roles/certbot/files/hooks/nginx.sh

32 lines
773 B
Bash
Raw Normal View History

2019-09-27 00:13:30 +02:00
#!/bin/sh
readonly VERBOSE=${VERBOSE:-"0"}
readonly QUIET=${QUIET:-"0"}
error() {
>&2 echo "${PROGNAME}: $1"
exit 1
}
debug() {
if [ "${VERBOSE}" = "1" ] && [ "${QUIET}" != "1" ]; then
>&2 echo "${PROGNAME}: $1"
fi
}
nginx_bin=$(command -v nginx)
if [ -n "$(pidof nginx)" ] && [ -n "${nginx_bin}" ]; then
if grep --dereference-recursive -E "letsencrypt" /etc/nginx/sites-enabled; then
if ${nginx_bin} -t > /dev/null; then
2019-09-27 00:13:30 +02:00
debug "Nginx detected... reloading"
systemctl reload nginx
else
error "Nginx config is broken, you must fix it !"
2019-09-27 00:13:30 +02:00
fi
else
debug "Nginx doesn't use Let's Encrypt certificate. Skip."
2019-09-27 00:13:30 +02:00
fi
else
debug "Nginx is not running or missing. Skip."
2019-09-27 00:13:30 +02:00
fi