Skip to content

Commit 0902d7e

Browse files
authored
Merge pull request #30 from JedMeister/dehydrated-cron-log
Refactor dehydrated cron job to only log renewal attempt by default.
2 parents 066cade + ef1e406 commit 0902d7e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

share/letsencrypt/dehydrated-confconsole.cron

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,28 @@
33
export PATH=$PATH:/usr/sbin
44

55
CERT=/etc/ssl/private/cert.pem
6+
RENEW=2592000 # seconds to cert expiry to try renew: 2592000 = 30 days
67
LOG=/var/log/confconsole/letsencrypt.log
8+
LOG_INFO= # set to always log certificate expiry check
79
DEHYDRATED=/usr/lib/confconsole/plugins.d/Lets_Encrypt/dehydrated-wrapper
810
ARG="--force"
911

1012
log() {
11-
echo "[$(date "+%Y-%m-%d %H:%M:%S")] cron: ${1}" >> $LOG
13+
echo -ne "[$(date "+%Y-%m-%d %H:%M:%S")] cron: ${1}" >> $LOG
1214
}
1315

14-
if $(which openssl) x509 -checkend 2592000 -noout -in $CERT; then
15-
log "$CERT does not require renewal. Nothing to do."
16+
exit_code=0
17+
check_cert_expire=$($(which openssl) x509 -checkend $RENEW -noout -in $CERT) \
18+
|| exit_code=$?
19+
msg="${CERT}: ${check_cert_expire} within $(( $RENEW / 60 / 60 / 24 )) days"
20+
21+
if [ "$exit_code" -eq 0 ]; then
22+
[ -z "$LOG_INFO" ] \
23+
|| log "${msg}. Nothing to do.\n"
1624
else
17-
log "$CERT has expired or will do so within 30 days. Attempting renewal."
25+
log "${msg} (or has already). Attempting renewal.\n"
1826
$DEHYDRATED $ARG
1927
if [ $? -ne 0 ]; then
20-
log "ERROR: $(basename $DEHYDRATED) exited with a non-zero exit code."
28+
log "ERR: $(basename $DEHYDRATED) exited with a non-zero exit code.\n"
2129
fi
2230
fi
23-

0 commit comments

Comments
 (0)