nginx-s3/overlay/usr/local/bin/entrypoint
Robert Kaussow bb2b33c798
All checks were successful
continuous-integration/drone/push Build is passing
intial s3 proxy setup
2023-09-23 14:17:09 +02:00

58 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env sh
# shellcheck disable=SC1091
. /usr/local/lib/log.sh
start_server() {
log_info "Start nginx server"
if ! nginx -q -g 'daemon off;' -t; then
log_error 'Nginx config validation failed, exit'
exit 1
fi
exec nginx -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 -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 vhost=/etc/proxy-config/vhost.yml -o /etc/nginx/conf.d/vhost.conf -f /etc/templates/vhost.conf.tmpl --chmod "0640"
while inotifywait -q --timefmt "%F %T" --format "%T [INFO] [$(basename "$0")] %e %f" -e modify,move,create,delete /etc/proxy-config/vhost.yml; do
log_info "Regenerate nginx config"
/usr/local/bin/gomplate -d vhost=/etc/proxy-config/vhost.yml -o /etc/nginx/conf.d/vhost.conf -f /etc/templates/vhost.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