From 642614cdad5f8f954c3eadf79f2c9e7db53d867e Mon Sep 17 00:00:00 2001 From: Bruno Zell Date: Wed, 3 Oct 2018 05:31:43 +0200 Subject: [PATCH] use domains private key file as timestamp --- src/scripts/run_certbot.sh | 5 +---- src/scripts/util.sh | 13 +++---------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/scripts/run_certbot.sh b/src/scripts/run_certbot.sh index 066799b..346589d 100644 --- a/src/scripts/run_certbot.sh +++ b/src/scripts/run_certbot.sh @@ -16,10 +16,7 @@ for domain in $(parse_domains); do if is_renewal_required $domain; then # Renewal required for this doman. # Last one happened over a week ago (or never) - if get_certificate $domain $CERTBOT_EMAIL; then - # Renewal successful. Update timestamp... - update_renewal_timestamp $domain - else + if ! get_certificate $domain $CERTBOT_EMAIL; then error "Cerbot failed for $domain. Check the logs for details." exit_code=1 fi diff --git a/src/scripts/util.sh b/src/scripts/util.sh index eb0243b..2c47c7d 100644 --- a/src/scripts/util.sh +++ b/src/scripts/util.sh @@ -80,8 +80,8 @@ get_certificate() { # ran over a week ago or never happened yet), otherwise return false. is_renewal_required() { # If the file does not exist assume a renewal is required - last_renewal_file="/etc/letsencrypt/$1_last_renewal.txt" - [[ ! -e "$last_renewal_file" ]] && return; + last_renewal_file="/etc/letsencrypt/live/$1/privkey.pem" + [ ! -e "$last_renewal_file" ] && return; # If the file exists, check if the last renewal was more than a week ago one_week_sec=604800 @@ -89,12 +89,5 @@ is_renewal_required() { last_renewal_sec=$(stat -c %Y "$last_renewal_file") last_renewal_delta_sec=$(( ($now_sec - $last_renewal_sec) )) is_finshed_week_sec=$(( ($one_week_sec - $last_renewal_delta_sec) )) - [[ $is_finshed_week_sec -lt 0 ]] -} - -# Given a domain name, set the current time as the last renewal timestamp -# as read by is_renewal_required(). -update_renewal_timestamp() { - last_renewal_file="/etc/letsencrypt/$1_last_renewal.txt" - touch "$last_renewal_file" + [ $is_finshed_week_sec -lt 0 ] }