Skip to content

Commit

Permalink
call certbot only once
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoZell committed Sep 28, 2018
1 parent 00d0b9b commit f7668d4
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f7668d4

Please sign in to comment.