-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcertbot.sh
executable file
·27 lines (19 loc) · 979 Bytes
/
certbot.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
#!/bin/bash
# example cron job to renew all certs due for renewal every sunday at 10:09pm
# 9 22 * * 0 /bin/bash -c "cd /path/to/dockerbunker && ./certbot.sh"
/bin/date | /usr/bin/tee -a /var/log/certbot.log
# Find base dir
while true;do /bin/ls | /bin/grep -q dockerbunker.sh;if [[ $? == 0 ]];then BASE_DIR=$PWD;break;else cd ../;fi;done
. "${BASE_DIR}"/data/include/init.sh
/usr/bin/docker run \
--rm --name=certbot \
--network dockerbunker-network \
-v "${CONF_DIR}"/nginx/ssl/letsencrypt:/etc/letsencrypt \
-v "${BASE_DIR}"/data/web:/var/www/html:rw \
certbot/certbot renew | /usr/bin/tee -a /var/log/certbot.log
if /usr/bin/docker exec -t nginx-dockerbunker nginx -t | grep -q 'test is successful';then
/usr/bin/docker restart nginx-dockerbunker >/dev/null
[[ $? == 0 ]] \
&& echo "Successfully restarted nginx-dockerbunker" | /usr/bin/tee -a /var/log/certbot.log \
|| echo "Restart of nginx-dockerbunker failed" | /usr/bin/tee -a /var/log/certbot.log
fi