Dmitry Yu Okunev 4 years ago
parent
commit
93e44e25e7
2 changed files with 21 additions and 19 deletions
  1. 14 0
      generate-certificate-cron.sh
  2. 7 19
      reload-instance-list.sh

+ 14 - 0
generate-certificate-cron.sh

@@ -0,0 +1,14 @@
+#!/bin/bash
+PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin
+
+GENCERT_ARGS=(" -d $DASHBOARD ")
+
+for LINE in $(cat /etc/webaliases); do
+	IFS=":"; WORDS=($LINE); IFS="$oldIFS"
+	HOST="${WORDS[0]}"
+	GENCERT_ARGS+=" -d ${HOST} "
+done
+
+if [ "$(stat -c %Y /etc/webaliases)" -gt "$(stat -c %Y /etc/letsencrypt/live/sites/cert.pem)" ]; then
+	/root/bin/generate-certificate.sh ${GENCERT_ARGS[@]}
+fi

+ 7 - 19
reload-instance-list.sh

@@ -66,24 +66,6 @@ for OLD_ID in ${OLD_IDS_ID[@]}; do
 	mysql --defaults-file=/etc/mysql/debian.cnf pdns -Ne "DELETE FROM records WHERE domain_id='$DOMAIN_ID' AND name='$OLD_ID.$ZONE'"
 done
 
-# generating the certificate
-
-GENCERT_ARGS=(" -d $DASHBOARD ")
-
-#for LINE in ${CURRENT_INSTANCES[@]}; do
-#	IFS=","; WORDS=($LINE); IFS="$oldIFS"
-#	ID="${WORDS[0]}"
-#	GENCERT_ARGS+=" -d ${ID}.${ZONE_PUBLIC} "
-#done
-
-for LINE in $(cat /etc/webaliases); do
-	IFS=":"; WORDS=($LINE); IFS="$oldIFS"
-	HOST="${WORDS[0]}"
-	GENCERT_ARGS+=" -d ${HOST} "
-done
-
-/root/bin/generate-certificate.sh ${GENCERT_ARGS[@]}
-
 # generating haproxy config
 
 	cat > /etc/haproxy/gen-conf.d/050-frontends.conf <<EOF
@@ -147,10 +129,16 @@ for LINE in $(cat /etc/webaliases); do
 	use_backend backend_${ID}_external if host_${ID}_external
 EOF
 		ID_BACKEND_EXT_ISSET[$ID]=true
+		ADDR=""
+		if [ "${NEW_IP[$ID]}" = "" ]; then
+			ADDR="127.0.0.1:83"
+		else
+			ADDR="${NEW_IP[$ID]}:80"
+		fi
 		cat >> /etc/haproxy/gen-conf.d/060-backends.conf <<EOF
 backend backend_${ID}_external
 	mode http
-	server primary ${NEW_IP[$ID]}:80
+	server primary ${ADDR}
 EOF
 	fi
 done