-
Notifications
You must be signed in to change notification settings - Fork 0
/
renew-cert.sh
39 lines (29 loc) · 1.01 KB
/
renew-cert.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash
# LetsEncrypt renew script
# Usage: echo "0 0 1 * * your_project_path/renew-cert.sh" >> /etc/crontab
# Author: https://omarghader.github.io/haproxy-letsencrypt-docker-certbot-certificates/
set -e
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
cd $DIR
echo "$(date) About to renew certificate" >> /var/log/letsencrypt-renew.log
/usr/bin/docker run \
-i \
--rm \
--name certbot \
-v $PWD/letsencrypt:/etc/letsencrypt \
-v $PWD/webroot:/webroot \
certbot/certbot \
renew -w /webroot
echo "$(date) Cat certificate" >> /var/log/letsencrypt-renew.log
function cat-cert() {
dir="./letsencrypt/live/$1"
cat "$dir/privkey.pem" "$dir/fullchain.pem" > "./certs/$1.pem"
}
for dir in ./letsencrypt/live/*; do
if [[ "$dir" != *"README" ]]; then
cat-cert $(basename "$dir")
fi
done
echo "$(date) Reload haproxy" >> /var/log/letsencrypt-renew.log
docker service update --force proxy_proxy
echo "$(date) Done" >> /var/log/letsencrypt-renew.log