48 lines
1.2 KiB
Bash
48 lines
1.2 KiB
Bash
#!/bin/bash
|
|
|
|
# When we get killed, kill all our children
|
|
trap "exit" INT TERM
|
|
trap "kill 0" EXIT
|
|
|
|
# Source in util.sh so we can have our nice tools
|
|
. $(cd $(dirname $0); pwd)/util.sh
|
|
|
|
# first include any user configs if they've been mounted
|
|
template_user_configs
|
|
|
|
# Immediately run auto_enable_configs so that nginx is in a runnable state
|
|
auto_enable_configs
|
|
|
|
# Start up nginx, save PID so we can reload config inside of run_certbot.sh
|
|
nginx -g "daemon off;" &
|
|
export NGINX_PID=$!
|
|
|
|
# Lastly, run startup scripts
|
|
for f in /scripts/startup/*.sh; do
|
|
if [ -x "$f" ]; then
|
|
echo "Running startup script $f"
|
|
$f
|
|
fi
|
|
done
|
|
echo "Done with startup"
|
|
|
|
# Instead of trying to run `cron` or something like that, just sleep and run `certbot`.
|
|
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).
|
|
# If nginx quit for whatever reason then stop the container.
|
|
# Leave the restart decision to the container orchestration.
|
|
if ! jobs | grep --quiet nginx ; then
|
|
exit 1
|
|
fi
|
|
done
|