Protect against wedged `nginx` startups
If `nginx` starts up incorrectly, we'll end up waiting a week for it to start up. Instead, fail out first.
This commit is contained in:
parent
e852dc607d
commit
4486e47861
|
@ -15,7 +15,7 @@ auto_enable_configs
|
||||||
|
|
||||||
# Start up nginx, save PID so we can reload config inside of run_certbot.sh
|
# Start up nginx, save PID so we can reload config inside of run_certbot.sh
|
||||||
nginx -g "daemon off;" &
|
nginx -g "daemon off;" &
|
||||||
export NGINX_PID=$!
|
NGINX_PID=$!
|
||||||
|
|
||||||
# Lastly, run startup scripts
|
# Lastly, run startup scripts
|
||||||
for f in /scripts/startup/*.sh; do
|
for f in /scripts/startup/*.sh; do
|
||||||
|
@ -28,20 +28,22 @@ echo "Done with startup"
|
||||||
|
|
||||||
# Instead of trying to run `cron` or something like that, just sleep and run `certbot`.
|
# Instead of trying to run `cron` or something like that, just sleep and run `certbot`.
|
||||||
while [ true ]; do
|
while [ true ]; do
|
||||||
echo "Run certbot"
|
|
||||||
/scripts/run_certbot.sh
|
|
||||||
|
|
||||||
# Sleep for 1 week
|
|
||||||
sleep 604810 &
|
|
||||||
SLEEP_PID=$!
|
|
||||||
|
|
||||||
# Wait for 1 week sleep or nginx
|
|
||||||
wait -n $SLEEP_PID $NGINX_PID
|
|
||||||
|
|
||||||
# Make sure we do not run container empty (without nginx process).
|
# Make sure we do not run container empty (without nginx process).
|
||||||
# If nginx quit for whatever reason then stop the container.
|
# If nginx quit for whatever reason then stop the container.
|
||||||
# Leave the restart decision to the container orchestration.
|
# Leave the restart decision to the container orchestration.
|
||||||
if ! jobs | grep --quiet nginx ; then
|
if ! jobs | grep --quiet nginx ; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Run certbot, tell nginx to reload its config
|
||||||
|
echo "Run certbot"
|
||||||
|
/scripts/run_certbot.sh
|
||||||
|
kill -HUP $NGINX_PID
|
||||||
|
|
||||||
|
# Sleep for 1 week
|
||||||
|
sleep 604810 &
|
||||||
|
SLEEP_PID=$!
|
||||||
|
|
||||||
|
# Wait for 1 week sleep or nginx
|
||||||
|
wait -n "$SLEEP_PID" "$NGINX_PID"
|
||||||
done
|
done
|
||||||
|
|
|
@ -29,8 +29,5 @@ done
|
||||||
# did indeed get certificates for
|
# did indeed get certificates for
|
||||||
auto_enable_configs
|
auto_enable_configs
|
||||||
|
|
||||||
# Finally, tell nginx to reload the configs
|
|
||||||
kill -HUP $NGINX_PID
|
|
||||||
|
|
||||||
set +x
|
set +x
|
||||||
exit $exit_code
|
exit $exit_code
|
||||||
|
|
Loading…
Reference in New Issue