Dmitry Yu Okunev 4 years ago
parent
commit
524cc47441
1 changed files with 18 additions and 3 deletions
  1. 18 3
      reload-instance-list.sh

+ 18 - 3
reload-instance-list.sh

@@ -26,6 +26,7 @@ oldIFS="$IFS"
 
 declare -A OLD_IDS_IP
 declare -A OLD_IDS_ID
+declare -A NEW_IP
 
 for LINE in $(pdnsutil list-zone "$ZONE" 2>/dev/null | sed -e "s/\\.$ZONE//g" | tr "\t" "@"); do
 	IFS="@"; WORDS=($LINE); IFS="$oldIFS"
@@ -55,6 +56,7 @@ for LINE in ${CURRENT_INSTANCES[@]}; do
 	fi
 	OLD_IDS_IP[$ID]=""
 	OLD_IDS_ID[$ID]=""
+	NEW_IP[$ID]="$IP"
 done
 
 for OLD_ID in ${OLD_IDS_ID[@]}; do
@@ -80,7 +82,7 @@ for LINE in $(cat /etc/webaliases); do
 	GENCERT_ARGS+=" -d ${HOST} "
 done
 
-/root/bin/generate-certificate.sh ${GENCERT_ARGS[@]}
+#/root/bin/generate-certificate.sh ${GENCERT_ARGS[@]}
 
 # generating haproxy config
 
@@ -119,6 +121,8 @@ EOF
 	#server backup1 192.168.1.132:80 check backup inter 25s
 done
 
+declare -A ID_BACKEND_EXT_ISSET
+
 for LINE in $(cat /etc/webaliases); do
 	IFS=":"; WORDS=($LINE); IFS="$oldIFS"
 	HOST="${WORDS[0]}"
@@ -131,13 +135,24 @@ for LINE in $(cat /etc/webaliases); do
 
 	cat >> /etc/haproxy/gen-conf.d/050-frontends.conf <<EOF
 	acl host_${ID}_external hdr(host) -i ${HOST}
+EOF
+done
+
+for LINE in $(cat /etc/webaliases); do
+	IFS=":"; WORDS=($LINE); IFS="$oldIFS"
+	HOST="${WORDS[0]}"
+	ID="${WORDS[1]}"
+	if [ "${ID_BACKEND_EXT_ISSET[$ID]}" = '' ]; then
+		cat >> /etc/haproxy/gen-conf.d/050-frontends.conf <<EOF
 	use_backend backend_${ID}_external if host_${ID}_external
 EOF
-	cat >> /etc/haproxy/gen-conf.d/060-backends.conf <<EOF
+		ID_BACKEND_EXT_ISSET[$ID]=true
+		cat >> /etc/haproxy/gen-conf.d/060-backends.conf <<EOF
 backend backend_${ID}_external
 	mode http
-	server primary ${IP}:80
+	server primary ${NEW_IP[$ID]}:80
 EOF
+	fi
 done
 
 cat /etc/haproxy/gen-conf.d/* > /etc/haproxy/haproxy.cfg