Browse Source

Prevent useless sleep in first iteration

As the script is normaly already run at nearly random time, the sleep
is unnesseccary before we requested a letsencrypt cert. Also we do not
need to sleep if the cert is still valid long enough.
Jonathan Golder 2 years ago
parent
commit
418377395d
Signed by: Jonathan Golder <jonathan@golderweb.de> GPG Key ID: A63CA3193092AD20
1 changed files with 7 additions and 1 deletions
  1. 7
    1
      letsencrypt-renew.sh

+ 7
- 1
letsencrypt-renew.sh View File

@@ -28,6 +28,9 @@
28 28
 
29 29
 PATH=/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
30 30
 
31
+# Detect first iteration to prevent useless sleep
32
+FIRSTITER=1
33
+
31 34
 # PATH to inifiles / letsencrypt dir
32 35
 if [ -z "${LECONFIGDIR}" ]; then
33 36
 	LECONFIGDIR=~/.config/letsencrypt
@@ -46,12 +49,15 @@ for inifile in "${LECONFIGDIR}"/cli-*.ini; do
46 49
 	domain=$(grep -e "[ \t]*domains.*" "${inifile}" | sed "s/ //g" |cut -d "=" -f2 | cut -d "," -f1)
47 50
 
48 51
 	# sleep for a random time so not all certificates get renewed at the same time
49
-	sleep $(expr $RANDOM % 600)
52
+	if [ $FIRSTITER -ne 1 ]; then
53
+		sleep $(expr $RANDOM % 600)
54
+	fi
50 55
 
51 56
 	# Check validity of cert for domain
52 57
 	openssl x509 -checkend $(( 21 * 86400 )) -in "${LECONFIGDIR}/live/${domain}/cert.pem" > /dev/null && continue
53 58
 
54 59
 	# run let's encrypt
60
+	FIRSTITER=0
55 61
 	letsencrypt certonly -c "${inifile}" || continue
56 62
 
57 63
 	# import certificate