From f7668d4347c545d26334a3e7fdcafddde2c90eab Mon Sep 17 00:00:00 2001 From: Bruno Zell Date: Fri, 28 Sep 2018 15:58:30 +0200 Subject: [PATCH] call certbot only once --- src/scripts/entrypoint.sh | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/scripts/entrypoint.sh b/src/scripts/entrypoint.sh index ba6f2c1..8885434 100644 --- a/src/scripts/entrypoint.sh +++ b/src/scripts/entrypoint.sh @@ -24,38 +24,29 @@ done echo "Done with startup" last_sync_file="/etc/letsencrypt/last_sync.txt" - -if [ ! -e "$last_sync_file" ]; then - touch "$last_sync_file" - - # run certbot to request all the ssl certs we can find - echo "Run first time certbot" - /scripts/run_certbot.sh -fi - one_week_sec=604800 -# Instead of trying to run `cron` or something like that, just leep and run `certbot`. +# Instead of trying to run `cron` or something like that, just sleep and run `certbot`. while [ true ]; do - # Sleep for 1 week - sleep 604810 & - SLEEP_PID=$! - 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 + if [ ! -e "$last_sync_file" ] || [ $is_finshed_week_sec -lt 0 ]; then # recreate the file touch "$last_sync_file" - # re-run certbot + # run certbot to request all the ssl certs we can find echo "Run certbot" /scripts/run_certbot.sh fi + # Sleep for 1 week + sleep 604810 & + SLEEP_PID=$! + # Wait on sleep so that when we get ctrl-c'ed it kills everything due to our trap wait "$SLEEP_PID" done