fix email call, add cron example
This commit is contained in:
parent
a120885920
commit
d9a6099d14
2 changed files with 28 additions and 6 deletions
11
update-mailcow-certs-cron
Normal file
11
update-mailcow-certs-cron
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# /etc/cron.d/update-mailcow-certs-cron - ensure we're using the latest mailcow certs...
|
||||||
|
#
|
||||||
|
# Check daily...
|
||||||
|
#
|
||||||
|
# Eventually, this will be an opportunity to validate certificates
|
||||||
|
# haven't been revoked, etc. Renewal will only occur if expiration
|
||||||
|
# is within 30 days.
|
||||||
|
SHELL=/bin/sh
|
||||||
|
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
||||||
|
|
||||||
|
0 2 * * * root /home/data/scripts/update-mailcow-certs/update-mailcow-certs.sh
|
|
@ -8,9 +8,9 @@ VERBOSE=1
|
||||||
# send an email, setting default subject...
|
# send an email, setting default subject...
|
||||||
EMAIL_SUBJ="MailCow cert for $DOMAIN"
|
EMAIL_SUBJ="MailCow cert for $DOMAIN"
|
||||||
#
|
#
|
||||||
EMAIL=sysadmin@oerfoundation.org
|
EMAIL=dave@davelane.nz
|
||||||
# Mailcow stuff
|
# Mailcow stuff
|
||||||
DOMAIN=about.oerfoundation.org
|
DOMAIN=moe.lane.net.nz
|
||||||
MCDIR=/home/docker/mailcow
|
MCDIR=/home/docker/mailcow
|
||||||
SSLDIR=data/assets/ssl
|
SSLDIR=data/assets/ssl
|
||||||
MCCA=$MCDIR/$SSLDIR/cert.pem
|
MCCA=$MCDIR/$SSLDIR/cert.pem
|
||||||
|
@ -29,6 +29,8 @@ LS=`which ls`
|
||||||
DATE=`date '+%Y-%m-%d'`
|
DATE=`date '+%Y-%m-%d'`
|
||||||
# email program
|
# email program
|
||||||
MAIL=`which mail`
|
MAIL=`which mail`
|
||||||
|
# docker-compose
|
||||||
|
DC=`which docker-compose`
|
||||||
# temporary holding point for email
|
# temporary holding point for email
|
||||||
TMP_EMAIL=/tmp/tmp_email.$0.$DATE_$TIME
|
TMP_EMAIL=/tmp/tmp_email.$0.$DATE_$TIME
|
||||||
#
|
#
|
||||||
|
@ -81,15 +83,23 @@ send_email_report() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
restart_mailcow() {
|
||||||
|
CWD=`pwd`
|
||||||
|
cd $MCDIR
|
||||||
|
# restart the mailcow app
|
||||||
|
$DC stop && $DC up -d
|
||||||
|
cd $CWD
|
||||||
|
}
|
||||||
|
|
||||||
# get the dates for the files...
|
# get the dates for the files...
|
||||||
MCCA_DATE=$(getfiledate $MCCA)
|
MCCA_DATE=$(getfiledate $MCCA)
|
||||||
#MCPRIV_DATE=$(getfiledate $MCPRIV_DATE)
|
MCPRIV_DATE=$(getfiledate $MCPRIV_DATE)
|
||||||
LECA_DATE=$(getfiledate $LECA)
|
LECA_DATE=$(getfiledate $LECA)
|
||||||
#LEPRIV_DATE=$(getfiledate $LEPRIV_DATE)
|
LEPRIV_DATE=$(getfiledate $LEPRIV_DATE)
|
||||||
|
|
||||||
# is the Let's Encrypt CA more recent than that used by Mailcow?
|
# is the Let's Encrypt CA more recent than that used by Mailcow?
|
||||||
# If so - update the Mailcow ones, reload Mailcow, and alert the webmaster
|
# If so - update the Mailcow ones, reload Mailcow, and alert the webmaster
|
||||||
|
EX=0
|
||||||
if (( "$LECA_DATE" > "$MCCA_DATE" )) ; then
|
if (( "$LECA_DATE" > "$MCCA_DATE" )) ; then
|
||||||
create_tmp_email
|
create_tmp_email
|
||||||
message "Need to update MailCow certs for $DOMAIN!"
|
message "Need to update MailCow certs for $DOMAIN!"
|
||||||
|
@ -104,17 +114,18 @@ if (( "$LECA_DATE" > "$MCCA_DATE" )) ; then
|
||||||
MCCA_DATE=$(getfiledate $MCCA)
|
MCCA_DATE=$(getfiledate $MCCA)
|
||||||
MCPRIV_DATE=$(getfiledate $MCPRIV_DATE)
|
MCPRIV_DATE=$(getfiledate $MCPRIV_DATE)
|
||||||
if (( "$MCCA_DATE" < "$LECA_DATE" && "$MCPRIV_DATE" < "$LECAPRIV_DATE" )) ; then
|
if (( "$MCCA_DATE" < "$LECA_DATE" && "$MCPRIV_DATE" < "$LECAPRIV_DATE" )) ; then
|
||||||
|
restart_mailcow
|
||||||
msg="Updated $MCCA and $MCPRIV at $TIMESTAMP"
|
msg="Updated $MCCA and $MCPRIV at $TIMESTAMP"
|
||||||
EMAIL_SUBJ='Success! '${EMAIL_SUBJ}
|
EMAIL_SUBJ='Success! '${EMAIL_SUBJ}
|
||||||
else
|
else
|
||||||
msg="Failed to update $MCCA and $MCPRIV at $TIMESTAMP"
|
msg="Failed to update $MCCA and $MCPRIV at $TIMESTAMP"
|
||||||
EMAIL_SUBJ='Failed! '${EMAIL_SUBJ}
|
EMAIL_SUBJ='Failed! '${EMAIL_SUBJ}
|
||||||
|
EX=0
|
||||||
fi
|
fi
|
||||||
message $msg
|
message $msg
|
||||||
email $msg
|
|
||||||
send_email_report
|
send_email_report
|
||||||
else
|
else
|
||||||
message "MailCow certs for $DOMAIN still current..."
|
message "MailCow certs for $DOMAIN still current..."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
exit $EX
|
||||||
|
|
Loading…
Reference in a new issue