Skip to content

Commit

Permalink
[Let's Encrypt] Add extended logging of cron task execution jelastic-…
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarenkoalexey authored May 30, 2024
1 parent 0260452 commit a14283c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions scripts/auto-update-ssl-cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GIT=$(which git);
BASE_REPO_URL="https://github.com/jelastic-jps/lets-encrypt"
RAW_REPO_SCRIPS_URL="https://raw.githubusercontent.com/jelastic-jps/lets-encrypt/master/scripts/"
SETTINGS_CUSTOM="/var/lib/jelastic/keys/letsencrypt/settings-custom"
LOG_FILE="/var/log/letsencrypt.log"

[[ -z "$WGET" || -z "$OPENSSL" || -z "$GREP" || -z "$SED" || -z "$GIT" ]] && { echo "PATH not set with neccessary commands"; exit 3 ; }

Expand Down Expand Up @@ -68,16 +69,17 @@ seconds_before_expire=$(( $DAYS_BEFORE_EXPIRE * 24 * 60 * 60 ));
$( [[ -e /usr/bin/python ]] || ln -s /usr/bin/python3 /usr/bin/python )
[[ -f "/var/lib/jelastic/SSL/jelastic.crt" && "$withExtIp" != "false" ]] && exp_date=$(jem ssl checkdomain | python -c "import sys, json; print (json.load(sys.stdin)['expiredate'])");

[ -z "$exp_date" ] && { echo "$(date) - no certificates for update" >> /var/log/letsencrypt.log; exit 0; };
[ -z "$exp_date" ] && { echo "$(date) - no certificates for update" >> ${LOG_FILE}; exit 0; };

_exp_date_unixtime=$(date --date="$exp_date" "+%s");
_cur_date_unixtime=$(date "+%s");
_delta_time=$(( $_exp_date_unixtime - $_cur_date_unixtime ));

[[ $_delta_time -le $seconds_before_expire ]] && {
echo "$(date) - update required" >> /var/log/letsencrypt.log;
echo "$(date) - update required" >> ${LOG_FILE};
validateLatestVersion
resp=$($WGET --no-check-certificate -qO- "${auto_update_url}");
echo ${resp} >> ${LOG_FILE};
[[ $? -ne 0 ]] && [[ -z $resp ]] && resp="Temporary network Issue";
{ echo "${resp#*response*}" | sed 's/"//g' | grep -q 'result:0' ;} || $WGET -qO- "${jerror_url}/jerror?appid=$appid&actionname=updatefromcontainer&callparameters=$auto_update_url&email=$email&errorcode=4121&errormessage=$resp&priority=high"
}
Expand Down

0 comments on commit a14283c

Please sign in to comment.