Created
January 14, 2016 12:02
-
-
Save tech-nova/6e2b06a08ba532f05d2b to your computer and use it in GitHub Desktop.
Script pour renouveler le certificat Letsencrypt lorsqu'il a moins de 30 jours de validité
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Avec /etc/cron.d/check-letsencrypt pour renouveler le certificat Letsencrypt | |
# 30 1 * * 1 root /usr/local/sbin/le-renew-webroot >> /var/log/le-renewal.log | |
# Configuration de nginx : centminmod | |
web_service='nginx' | |
domain='epoxit.com' | |
config_file="/home/nginx/domains/$domain/private/letsencrypt/le-renew-webroot.ini" | |
le_path='/opt/letsencrypt' | |
exp_limit=30; | |
if [ ! -f $config_file ]; then | |
echo "[ERROR] config file does not exist: $config_file" | |
exit 1; | |
fi | |
#domain=`grep "^\s*domains" $config_file | sed "s/^\s*domains\s*=\s*//" | sed 's/(\s*)\|,.*$//'` | |
cert_file="/etc/letsencrypt/live/$domain/fullchain.pem" | |
if [ ! -f $cert_file ]; then | |
echo "[ERROR] certificate file not found for domain $domain." | |
fi | |
exp=$(date -d "`openssl x509 -in $cert_file -text -noout|grep "Not After"|cut -c 25-`" +%s) | |
datenow=$(date -d "now" +%s) | |
days_exp=$(echo \( $exp - $datenow \) / 86400 |bc) | |
echo "Checking expiration date for $domain..." | |
if [ "$days_exp" -gt "$exp_limit" ] ; then | |
echo "The certificate is up to date, no need for renewal ($days_exp days left)." | |
exit 0; | |
else | |
echo "The certificate for $domain is about to expire soon. Starting webroot renewal script..." | |
echo "Desactivation du Firewall" | |
csf --stop | |
$le_path/letsencrypt-auto certonly -a webroot --agree-tos --renew-by-default --config $config_file | |
echo "Activation du Firewall" | |
csf --start | |
echo "Reloading $web_service" | |
/usr/sbin/service $web_service reload | |
echo "Renewal process finished for domain $domain" | |
exit 0; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment