Zimbra letsencrypt ssl renew
Перейти к навигации
Перейти к поиску
Скрипт для автоматического обновления ссл сертификата от letsencrypt. Обновляет сертификат за 10 дней до истичения. Вызывается кроном с передачей доменного имени Zimbra сервера.
crontab -l
0 0 * * * /usr/local/sbin/letsencrypt_renew.sh `hostname`
Скрипт
#!/bin/bash
export TZ=GMT
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
domain=$1
renew_date=`date +"%b %d %Y" -d "-10 days"`
renew_month=`echo ${renew_date} | awk -F' ' {' print $1 '}`
renew_day=`echo ${renew_date} | awk -F' ' {' print $2 '}`
exp_date=`echo | openssl s_client -servername ${domain} -connect ${domain}:443 2>/dev/null | openssl x509 -noout -dates | grep notAfter | awk -F'=' {'print $2'}`
exp_month=`echo ${exp_date} | awk -F' ' {' print $1 '}`
exp_day=`echo ${exp_date} | awk -F' ' {' print $2 '}`
get_X3_root() {
wget https://www.identrust.com/node/935 -O /tmp/trustidrootx3_chain.p7b
openssl pkcs7 -inform DER -in /tmp/trustidrootx3_chain.p7b -print_certs -outform PEM -out /tmp/trustidrootx3_chain.pem
}
action_renew() {
sudo -u zimbra /opt/zimbra/bin/zmproxyctl stop
sudo -u zimbra /opt/zimbra/bin/zmmailboxdctl stop
letsencrypt renew --force-renewal
cd /opt/zimbra/ssl/letsencrypt/
cp /etc/letsencrypt/live/${domain}/* .
chown zimbra:zimbra /opt/zimbra/ssl/letsencrypt/*
cat /tmp/trustidrootx3_chain.pem >> /opt/zimbra/ssl/letsencrypt/chain.pem
rm -f /tmp/trustidrootx3_chain.pem
/opt/zimbra/bin/zmcertmgr verifycrt comm privkey.pem cert.pem chain.pem
cp -a /opt/zimbra/ssl/zimbra /opt/zimbra/ssl/zimbra.$(date "+%Y%m%d")
cp /opt/zimbra/ssl/letsencrypt/privkey.pem /opt/zimbra/ssl/zimbra/commercial/commercial.key
sudo -u zimbra /opt/zimbra/bin/zmcertmgr deploycrt comm cert.pem chain.pem
sudo -u zimbra /opt/zimbra/bin/zmcontrol restart
}
if [ ${exp_month} == ${renew_month} ]; then
if [ ${exp_day} == ${renew_day} ]; then
get_X3_root
action_renew
fi
fi