Letsencrypt automatic script
Posted: Mon Dec 14, 2015 11:21 pm
Hello,
I've written a simple script to install and renew letsencrypt certificates.
I'm assuming you are using nginx as a proxy or web server. The script will try and generate a certificate for every domain of every user.
Here is how to use it.
1) Install git
2)Clone letsencrypt repository (I'm assuming you will be working as root in your /root directory):
3) create a /etc/letsencrypt directory and save a file in it called webroot.ini (just fill your correct email address)
4) edit the templates you are using situated in /usr/local/vesta/data/templates/web/nginx
the default ones are default.tpl and default.stpl
and add
in the server section. then reload your nginx configuration
5) create a script with the following content
and run it. It should obtain and install your certificates.
If you run it again it should renew the ones older than 60 days.
you can add it to your crontab and execute it twice a month.
good luck
I've written a simple script to install and renew letsencrypt certificates.
I'm assuming you are using nginx as a proxy or web server. The script will try and generate a certificate for every domain of every user.
Here is how to use it.
1) Install git
2)Clone letsencrypt repository (I'm assuming you will be working as root in your /root directory):
Code: Select all
user@webserver:~$ git clone https://github.com/letsencrypt/letsencrypt
user@webserver:~$ cd letsencrypt
Code: Select all
# webroot.ini general config ini
rsa-key-size = 4096
email = [email protected]
text = True
agree-tos = True
#agree-dev-preview = 1
renew-by-default = True
authenticator = webroot
webroot-path = /etc/letsencrypt
the default ones are default.tpl and default.stpl
and add
Code: Select all
location /.well-known/acme-challenge {
alias /etc/letsencrypt/.well-known/acme-challenge;
location ~ /.well-known/acme-challenge/(.*) {
add_header Content-Type text/plain;
}
}
5) create a script with the following content
Code: Select all
#!/bin/bash
#creates or renews (if older than 60 days) certificates for all domains
MAXAGE=$(echo '60*24*60*60' | bc) # seconds in 60 days
cd /root/letsencrypt
for u in $(v-list-users | cut -f1 -d' ' | tail -n+3)
do
for f in $(v-list-dns-domains $u | cut -f1 -d' ' | tail -n+3)
do
#FILEAGE=$(($(date +%s) - $(stat -c '%Y' "/etc/letsencrypt/live/$f")))
if [ ! -d "/etc/letsencrypt/live/$f" ] || [ ! $(($(date +%s) - $(stat -c '%Y' "/etc/letsencrypt/live/$f"))) -lt $MAXAGE ]; then
./letsencrypt-auto -c /etc/letsencrypt/webroot.ini -d $f -d www.$f certonly
[[ -e /etc/letsencrypt/live/$f ]] && cp -Lr --remove-destination /etc/letsencrypt/live/$f/fullchain.pem /home/$u/conf/web/ssl.$f.pem
[[ -e /etc/letsencrypt/live/$f ]] && cp -Lr --remove-destination /etc/letsencrypt/live/$f/privkey.pem /home/$u/conf/web/ssl.$f.key
[[ -e /etc/letsencrypt/live/$f ]] && cp -Lr --remove-destination /etc/letsencrypt/live/$f/cert.pem /home/$u/conf/web/ssl.$f.crt
[[ -e /etc/letsencrypt/live/$f ]] && cp -Lr --remove-destination /etc/letsencrypt/live/$f/chain.pem /home/$u/conf/web/ssl.$f.ca
fi
done
done
service nginx reload
cd "$OLDPWD"
If you run it again it should renew the ones older than 60 days.
you can add it to your crontab and execute it twice a month.
good luck