move interval management to a util funcion
This commit is contained in:
parent
1aa799bb70
commit
96897f8e37
|
@ -24,23 +24,18 @@ done
|
||||||
echo "Done with startup"
|
echo "Done with startup"
|
||||||
|
|
||||||
last_sync_file="/etc/letsencrypt/last_sync.txt"
|
last_sync_file="/etc/letsencrypt/last_sync.txt"
|
||||||
one_week_sec=604800
|
|
||||||
|
|
||||||
# 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
|
||||||
last_sync_sec=$(stat -c %Y "$last_sync_file")
|
if [ is_sync_required $last_sync_file ]; then
|
||||||
now_sec=$(date -d now +%s)
|
# recreate the file to persist the last sync timestamp
|
||||||
runned_sec=$(( ($now_sec - $last_sync_sec) ))
|
|
||||||
is_finshed_week_sec=$(( ($one_week_sec - $runned_sec) ))
|
|
||||||
|
|
||||||
echo "Not run_certbot.sh"
|
|
||||||
if [ ! -e "$last_sync_file" ] || [ $is_finshed_week_sec -lt 0 ]; then
|
|
||||||
# recreate the file
|
|
||||||
touch "$last_sync_file"
|
touch "$last_sync_file"
|
||||||
|
|
||||||
# run certbot to request all the ssl certs we can find
|
# run certbot to request all the ssl certs we can find
|
||||||
echo "Run certbot"
|
echo "Run certbot"
|
||||||
/scripts/run_certbot.sh
|
/scripts/run_certbot.sh
|
||||||
|
else
|
||||||
|
echo "Not run certbot"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Sleep for 1 week
|
# Sleep for 1 week
|
||||||
|
|
|
@ -75,3 +75,16 @@ get_certificate() {
|
||||||
$letsencrypt_url -d $1 --http-01-port 1337 \
|
$letsencrypt_url -d $1 --http-01-port 1337 \
|
||||||
--standalone --preferred-challenges http-01 --debug
|
--standalone --preferred-challenges http-01 --debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_sync_required() {
|
||||||
|
if [ ! -e "$1" ]; then
|
||||||
|
return true
|
||||||
|
fi
|
||||||
|
|
||||||
|
one_week_sec=604800
|
||||||
|
last_sync_sec=$(stat -c %Y "$1")
|
||||||
|
now_sec=$(date -d now +%s)
|
||||||
|
last_sync_delta_sec=$(( ($now_sec - $last_sync_sec) ))
|
||||||
|
is_finshed_week_sec=$(( ($one_week_sec - $last_sync_delta_sec) ))
|
||||||
|
return $is_finshed_week_sec -lt 0
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue