Robert Kaussow
3ee6e3c6ff
All checks were successful
continuous-integration/drone/push Build is passing
61 lines
1.6 KiB
Bash
Executable File
61 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
|
|
# shellcheck disable=SC3040
|
|
set -eo pipefail
|
|
|
|
# shellcheck disable=SC1091
|
|
. /usr/local/lib/log.sh
|
|
|
|
start_server() {
|
|
log_info "Start nginx server"
|
|
if ! nginx -e stderr -q -g 'daemon off;' -t; then
|
|
log_error 'Nginx config validation failed, exit'
|
|
exit 1
|
|
fi
|
|
|
|
exec nginx -e stderr -g "daemon off;" &
|
|
PID=$!
|
|
|
|
{
|
|
while true; do
|
|
inotifywait -rq --timefmt "%F %T" --format "%T [INFO] [$(basename "$0")] %e %f" -e modify,move,create,delete /etc/nginx/
|
|
log_info 'Detected nginx config update, run validation'
|
|
|
|
if ! nginx -e stderr -q -g 'daemon off;' -t; then
|
|
log_warn 'Nginx config validation failed, skip reload'
|
|
continue
|
|
fi
|
|
|
|
log_info 'Reload nginx to apply config update'
|
|
kill -HUP $PID
|
|
done
|
|
} &
|
|
|
|
wait $PID
|
|
}
|
|
|
|
run_config() {
|
|
log_info "Start nginx config service"
|
|
/usr/local/bin/gomplate -d config=/etc/nginx-s3/config.yaml -o /etc/nginx/conf.d/vhosts.conf -f /etc/templates/vhosts.conf.tmpl --chmod "0640"
|
|
|
|
while inotifywait -q --timefmt "%F %T" --format "%T [INFO] [$(basename "$0")] %e %f" -e modify,move,create,delete /etc/nginx-s3/config.yaml; do
|
|
log_info "Regenerate nginx config"
|
|
/usr/local/bin/gomplate -d config=/etc/nginx-s3/config.yaml -o /etc/nginx/conf.d/vhosts.conf -f /etc/templates/vhosts.conf.tmpl --chmod "0640"
|
|
done
|
|
}
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
server)
|
|
start_server
|
|
;;
|
|
config)
|
|
run_config
|
|
;;
|
|
*)
|
|
log_info "Unknown entrypoint option $1" >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|