2017-01-23 06:33:45 +00:00
|
|
|
#!/bin/sh
|
2017-01-20 02:17:56 +00:00
|
|
|
|
2017-01-23 06:33:45 +00:00
|
|
|
# When we get killed, kill all our children
|
2017-01-20 02:17:56 +00:00
|
|
|
trap "exit" INT TERM
|
|
|
|
trap "kill 0" EXIT
|
2017-01-23 06:33:45 +00:00
|
|
|
|
|
|
|
# Source in util.sh so we can have our nice tools
|
|
|
|
. $(cd $(dirname $0); pwd)/util.sh
|
|
|
|
|
|
|
|
# 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=$!
|
|
|
|
|
2017-06-20 18:27:05 +00:00
|
|
|
# Lastly, run startup scripts
|
|
|
|
for f in /scripts/startup/*.sh; do
|
2018-06-28 00:59:43 +00:00
|
|
|
if [ -x "$f" ]; then
|
2017-07-24 04:50:04 +00:00
|
|
|
echo "Running startup script $f"
|
|
|
|
$f
|
|
|
|
fi
|
2017-06-20 18:27:05 +00:00
|
|
|
done
|
2017-07-24 04:50:04 +00:00
|
|
|
echo "Done with startup"
|
2017-06-20 18:27:05 +00:00
|
|
|
|
2018-06-27 23:13:11 +00:00
|
|
|
last_sync_file="/etc/letsencrypt/last_sync.txt"
|
|
|
|
|
2018-06-28 00:59:43 +00:00
|
|
|
if [ ! -e "$last_sync_file" ]; then
|
2018-06-27 23:13:11 +00:00
|
|
|
touch "$last_sync_file"
|
2018-06-28 00:59:43 +00:00
|
|
|
|
|
|
|
# run certbot to request all the ssl certs we can find
|
|
|
|
echo "Run first time certbot"
|
|
|
|
/scripts/run_certbot.sh
|
2018-06-27 23:13:11 +00:00
|
|
|
fi
|
|
|
|
|
2018-06-28 00:59:43 +00:00
|
|
|
one_week_sec=604800
|
2018-06-27 23:13:11 +00:00
|
|
|
|
2018-05-02 06:03:42 +00:00
|
|
|
# Instead of trying to run `cron` or something like that, just leep and run `certbot`.
|
|
|
|
while [ true ]; do
|
|
|
|
# Sleep for 1 week
|
|
|
|
sleep 604800 &
|
|
|
|
SLEEP_PID=$!
|
|
|
|
|
2018-06-28 00:59:43 +00:00
|
|
|
last_sync_sec=$(stat -c %Y "$last_sync_file")
|
|
|
|
now_sec=$(date -d now +%s)
|
|
|
|
runned_sec=$(( ($now_sec - $last_sync_sec) ))
|
|
|
|
is_finshed_week_sec=$(( ($one_week_sec - $runned_sec) ))
|
|
|
|
|
|
|
|
echo "Not run_certbot.sh"
|
|
|
|
if [ $is_finshed_week_sec -lt 0 ]; then
|
|
|
|
# re-run certbot
|
|
|
|
echo "Run certbot"
|
|
|
|
/scripts/run_certbot.sh
|
|
|
|
fi
|
2018-05-02 06:03:42 +00:00
|
|
|
|
|
|
|
# Wait on sleep so that when we get ctrl-c'ed it kills everything due to our trap
|
|
|
|
wait "$SLEEP_PID"
|
|
|
|
done
|