__nginx_vhost: make configuration reload more robust
This commit is contained in:
parent
8db890deb4
commit
502cb54ce2
1 changed files with 30 additions and 21 deletions
|
@ -1,26 +1,35 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
os="$(cat "${__global:?}"/explorer/os)"
|
os="$(cat "${__global:?}"/explorer/os)"
|
||||||
|
init=$(cat "$__global/explorer/init")
|
||||||
|
nginx_confdir="/etc/nginx"
|
||||||
|
|
||||||
case "$os" in
|
# The nginx service is not automatically started on alpine.
|
||||||
alpine)
|
if [ "$os" = "alpine" ]; then
|
||||||
reload_hook="service nginx --ifstopped start;\
|
echo "service nginx --ifstopped start"
|
||||||
service nginx --ifstarted reload"
|
fi
|
||||||
;;
|
|
||||||
debian|ubuntu|*)
|
if grep -qE "^__file$nginx_confdir" "${__messages_in:?}"; then
|
||||||
reload_hook="systemctl reload-or-restart nginx"
|
case "$init" in
|
||||||
;;
|
systemd)
|
||||||
esac
|
reload_hook="systemctl reload-or-restart nginx"
|
||||||
|
;;
|
||||||
# Check configuration and reload if valid.
|
busybox-init+openrc)
|
||||||
# TODO: only check if configuration was changed (= listen for __file's
|
reload_hook="service nginx reload"
|
||||||
# messages).
|
;;
|
||||||
cat << EOF
|
*)
|
||||||
if nginx -t; then
|
echo "Unknown init $init." >&2
|
||||||
$reload_hook
|
exit 1
|
||||||
else
|
;;
|
||||||
echo "NGINX configuration is invalid. Exiting." >2&
|
esac
|
||||||
nginx -t >2&
|
|
||||||
exit 1
|
cat <<- EOF
|
||||||
|
if nginx -t; then
|
||||||
|
$reload_hook
|
||||||
|
else
|
||||||
|
echo "NGINX configuration is invalid. Exiting." >2&
|
||||||
|
nginx -t >2&
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
EOF
|
||||||
fi
|
fi
|
||||||
EOF
|
|
||||||
|
|
Loading…
Reference in a new issue