-
Notifications
You must be signed in to change notification settings - Fork 3
/
renew.sh
executable file
·45 lines (36 loc) · 1.01 KB
/
renew.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
40
41
42
43
44
45
#!/usr/bin/env bash
source ./config.sh
source ./logger.sh
DOMAIN=$(ls /etc/letsencrypt/live/*/cert.pem -1tr | awk -F/ 'NR==1{print $5}')
if [[ -z $DOMAIN ]]; then
log_warn "No live domain found, terminating."
exit
fi
log_info "Will use $DOMAIN to test challenge accessibility."
log_info "Starting http server ..."
python -m http.server 80 --directory $WEBROOT &
trap "kill $!" exit
sleep 5
FILE="$ACME_PATH/check-renew-$(date +%s)"
TEST_URL="http://$DOMAIN/$FILE"
log_info "Test challenge accessibility $TEST_URL ..."
echo "certbot" > $WEBROOT/$FILE
curl --silent -v --max-time 5 $TEST_URL > /tmp/result
ERR=$?
rm -f $WEBROOT/$FILE
if [ $ERR -ne 0 -o "$(cat /tmp/result)" != "certbot" ]; then
log_error "Test challenge failed $TEST_URL"
exit 1
fi
log_info "Calling certbot renew ..."
{
flock 200
certbot renew --webroot -w $WEBROOT --non-interactive
CERTBOT_RESULT=$?
} 200>$LOCK_FILE
if (( $CERTBOT_RESULT == 0 )); then
log_info "Cerbot ok."
./export.sh
else
log_error"Cerbot failed."
fi