Extract hook scripts for Apache and Nginx
This commit is contained in:
parent
97e4abb37c
commit
95e16287c8
47
evoacme/files/apahe_update_and_reload.sh
Normal file
47
evoacme/files/apahe_update_and_reload.sh
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
error() {
|
||||||
|
>&2 echo "${PROGNAME}: $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
debug() {
|
||||||
|
if [ "${VERBOSE}" = "1" ] && [ "${QUIET}" != "1" ]; then
|
||||||
|
>&2 echo "${PROGNAME}: $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly PROGNAME=$(basename "$0")
|
||||||
|
|
||||||
|
readonly VERBOSE=${VERBOSE:-"0"}
|
||||||
|
|
||||||
|
if [ -z "${EVOACME_VHOST_PATH}"]; then
|
||||||
|
error "Missing EVOACME_VHOST_PATH environment variable"
|
||||||
|
fi
|
||||||
|
if [ -z "${EVOACME_CERT_PATH}"]; then
|
||||||
|
error "Missing EVOACME_CERT_PATH environment variable"
|
||||||
|
fi
|
||||||
|
|
||||||
|
readonly APACHE2CTL_BIN=$(command -v apache2ctl) || error "apache2ctl command not installed"
|
||||||
|
|
||||||
|
[ -r "${EVOACME_VHOST_PATH}"] || error "File ${EVOACME_VHOST_PATH} is not readable"
|
||||||
|
|
||||||
|
local search="^SSLCertificateFile.*$"
|
||||||
|
local replace="SSLCertificateFile ${EVOACME_VHOST_PATH}"
|
||||||
|
|
||||||
|
if ! $(grep -qE "${search}" "${EVOACME_VHOST_PATH}"); then
|
||||||
|
[ -w "${EVOACME_VHOST_PATH}" ] || error "File ${EVOACME_VHOST_PATH} is not writable"
|
||||||
|
|
||||||
|
sed -i "s~${search}~${replace}~" "${EVOACME_VHOST_PATH}"
|
||||||
|
debug "Config in ${EVOACME_VHOST_PATH} has been updated"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$(pidof apache2)" ]; then
|
||||||
|
if $(${APACHE2CTL_BIN} -t 2> /dev/null); then
|
||||||
|
debug "Apache detected... reloading"
|
||||||
|
service apache2 reload
|
||||||
|
else
|
||||||
|
error "Apache config is broken, you must fix it !"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
47
evoacme/files/nginx_update_and_reload.sh
Normal file
47
evoacme/files/nginx_update_and_reload.sh
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
error() {
|
||||||
|
>&2 echo "${PROGNAME}: $1"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
debug() {
|
||||||
|
if [ "${VERBOSE}" = "1" ] && [ "${QUIET}" != "1" ]; then
|
||||||
|
>&2 echo "${PROGNAME}: $1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
readonly PROGNAME=$(basename "$0")
|
||||||
|
|
||||||
|
readonly VERBOSE=${VERBOSE:-"0"}
|
||||||
|
|
||||||
|
if [ -z "${EVOACME_VHOST_PATH}"]; then
|
||||||
|
error "Missing EVOACME_VHOST_PATH environment variable"
|
||||||
|
fi
|
||||||
|
if [ -z "${EVOACME_CERT_PATH}"]; then
|
||||||
|
error "Missing EVOACME_CERT_PATH environment variable"
|
||||||
|
fi
|
||||||
|
|
||||||
|
readonly NGINX_BIN=$(command -v nginx) || error "nginx command not installed"
|
||||||
|
|
||||||
|
[ -r "${EVOACME_VHOST_PATH}"] || error "File ${EVOACME_VHOST_PATH} is not readable"
|
||||||
|
|
||||||
|
readonly search="^ssl_certificate[^_].*$"
|
||||||
|
readonly replace="ssl_certificate ${EVOACME_CERT_PATH};"
|
||||||
|
|
||||||
|
if ! $(grep -qE "${search}" "${EVOACME_VHOST_PATH}"); then
|
||||||
|
[ -w "${EVOACME_VHOST_PATH}" ] || error "File ${EVOACME_VHOST_PATH} is not writable"
|
||||||
|
|
||||||
|
sed -i "s~${search}~${replace}~" "${EVOACME_VHOST_PATH}"
|
||||||
|
debug "Config in ${EVOACME_VHOST_PATH} has been updated"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$(pidof nginx)" ]; then
|
||||||
|
if $(${NGINX_BIN} -t 2> /dev/null); then
|
||||||
|
debug "Nginx detected... reloading"
|
||||||
|
service nginx reload
|
||||||
|
else
|
||||||
|
error "Nginx config is broken, you must fix it !"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
Loading…
Reference in a new issue