Auto renew let's encrypt ssl


Cron job run at every first day of month

1
0 0 1 * * /bin/bash /path/to/cron/renew-letsencrypt-ssl.sh

Auto renew ssl bash scripts

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/bash

# Config
DOMAINS="domain1.com domain2.com"
EMAIL="[email protected]"

# Stop nginx
service nginx stop

# Update ssl certs
for domain in $DOMAINS; do
echo "renew: $domain"

/path/to/letsencrypt-auto certonly -a standalone -d $domain --server https://acme-v01.api.letsencrypt.org/directory --agree-dev-preview --renew

if [ $? -ne 0 ]
then
ERRORLOG=`tail /var/log/letsencrypt/letsencrypt.log`
echo -e "The Lets Encrypt Cert has not been renewed! \n \n" $ERRORLOG | mail -s "Lets Encrypt Cert Alert" $EMAIL
fi
done

# Start nginx
service nginx start