Эх сурвалжийг харах

suspend remote dns if connection failed

Serghey Rodin 12 жил өмнө
parent
commit
f70ba768a3

+ 11 - 22
bin/v-add-remote-dns-domain

@@ -50,8 +50,10 @@ fi
 old_ifs="$IFS"
 IFS=$'\n'
 
-# Starting cluster loop
-for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
+# Check remote dns nodes
+remote_dns_health_check
+
+for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
 
     # Get host values
     eval $cluster_str
@@ -61,31 +63,17 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
         TYPE='api'
     fi
 
+    # Check recipient dns user
+    if [ -z "$DNS_USER" ]; then
+        DNS_USER='dns-cluster'
+    fi
+
     # Switch on connection type
     case $TYPE in
         ssh) send_cmd="send_ssh_cmd" ;;
         *)  send_cmd="send_api_cmd" ;;
     esac
 
-    # Check host connection
-    $send_cmd v-list-sys-config
-    if [ $? -ne 0 ]; then
-        echo "Error: $TYPE connection to $HOST failed"
-        log_event "$E_CONNECT $EVENT"
-        exit $E_CONNECT
-    fi
-
-    # Check recipient dns user
-    if [ -z "$DNS_USER" ]; then
-        DNS_USER='dns-cluster'
-    fi
-    $send_cmd v-list-user $DNS_USER
-    if [ $? -ne 0 ]; then
-        echo "Error: dns user $DNS_USER doesn't exist"
-        log_event "$E_NOTEXIST $EVENT"
-        exit $E_NOTEXIST
-    fi
-
     # Check dns exceptions
     if [ -z "$DNS_CLUSTER_IGNORE" ]; then
         DNS_CLUSTER_IGNORE='dns-cluster'
@@ -111,7 +99,7 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
     # Rebuild dns zone
     $send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled'
     if [ $? -ne 0 ]; then
-        echo "Error: $TYPE connection to $HOST failed (rebuild)"
+        echo "Error: $TYPE connection to $HOST failed"
         log_event "$E_CONNECT $EVENT"
         exit $E_CONNECT
     fi
@@ -119,6 +107,7 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
 done
 
 # Update pipe
+rm -f $tmpfile
 pipe="$VESTA/data/queue/dns-cluster.pipe"
 str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
 if [ ! -z "$str" ]; then

+ 3 - 16
bin/v-add-remote-dns-record

@@ -52,9 +52,10 @@ fi
 old_ifs="$IFS"
 IFS=$'\n'
 
-# Starting cluster loop
-for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
+# Check remote dns nodes
+remote_dns_health_check
 
+for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
     # Get host values
     eval $cluster_str
 
@@ -69,24 +70,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
         *)  send_cmd="send_api_cmd" ;;
     esac
 
-    # Check host connection
-    $send_cmd v-list-sys-config
-    if [ $? -ne 0 ]; then
-        echo "Error: $TYPE connection to $HOST failed"
-        log_event "$E_CONNECT $EVENT"
-        exit $E_CONNECT
-    fi
-
     # Check recipient dns user
     if [ -z "$DNS_USER" ]; then
         DNS_USER='dns-cluster'
     fi
-    $send_cmd v-list-user $DNS_USER
-    if [ $? -ne 0 ]; then
-        echo "Error: dns user $DNS_USER doesn't exist"
-        log_event "$E_NOTEXIST $EVENT"
-        exit $E_NOTEXIST
-    fi
 
     # Check dns exceptions
     if [ -z "$DNS_CLUSTER_IGNORE" ]; then

+ 9 - 16
bin/v-change-remote-dns-domain-exp

@@ -50,8 +50,10 @@ fi
 old_ifs="$IFS"
 IFS=$'\n'
 
-# Starting cluster loop
-for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
+# Check remote dns nodes
+remote_dns_health_check
+
+for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
 
     # Get host values
     eval $cluster_str
@@ -67,24 +69,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
         *)  send_cmd="send_api_cmd" ;;
     esac
 
-    # Check host connection
-    $send_cmd v-list-sys-config
-    if [ $? -ne 0 ]; then
-        echo "Error: $TYPE connection to $HOST failed"
-        log_event "$E_CONNECT $EVENT"
-        exit $E_CONNECT
-    fi
-
     # Check recipient dns user
     if [ -z "$DNS_USER" ]; then
         DNS_USER='dns-cluster'
     fi
-    $send_cmd v-list-user $DNS_USER
-    if [ $? -ne 0 ]; then
-        echo "Error: dns user $DNS_USER doesn't exist"
-        log_event "$E_NOTEXIST $EVENT"
-        exit $E_NOTEXIST
-    fi
 
     # Check dns exceptions
     if [ -z "$DNS_CLUSTER_IGNORE" ]; then
@@ -95,6 +83,11 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
     str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
     eval $str
     $send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'scheduled'
+    if [ $? -ne 0 ]; then
+        echo "Error: $TYPE connection to $HOST failed"
+        log_event "$E_CONNECT $EVENT"
+        exit $E_CONNECT
+    fi
 
 done
 

+ 4 - 16
bin/v-change-remote-dns-domain-soa

@@ -50,8 +50,10 @@ fi
 old_ifs="$IFS"
 IFS=$'\n'
 
-# Starting cluster loop
-for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
+# Check remote dns nodes
+remote_dns_health_check
+
+for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
 
     # Get host values
     eval $cluster_str
@@ -67,24 +69,10 @@ for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
         *)  send_cmd="send_api_cmd" ;;
     esac
 
-    # Check host connection
-    $send_cmd v-list-sys-config
-    if [ $? -ne 0 ]; then
-        echo "Error: $TYPE connection to $HOST failed"
-        log_event "$E_CONNECT $EVENT"
-        exit $E_CONNECT
-    fi
-
     # Check recipient dns user
     if [ -z "$DNS_USER" ]; then
         DNS_USER='dns-cluster'
     fi
-    $send_cmd v-list-user $DNS_USER
-    if [ $? -ne 0 ]; then
-        echo "Error: dns user $DNS_USER doesn't exist"
-        log_event "$E_NOTEXIST $EVENT"
-        exit $E_NOTEXIST
-    fi
 
     # Check dns exceptions
     if [ -z "$DNS_CLUSTER_IGNORE" ]; then

+ 4 - 1
bin/v-change-remote-dns-domain-ttl

@@ -50,8 +50,11 @@ fi
 old_ifs="$IFS"
 IFS=$'\n'
 
+# Check remote dns nodes
+remote_dns_health_check
+
 # Starting cluster loop
-for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
+for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
 
     # Get host values
     eval $cluster_str

+ 1 - 1
bin/v-list-remote-dsn-hosts → bin/v-list-remote-dns-hosts

@@ -32,7 +32,7 @@ if [ ! -e "$conf" ]; then
 fi
 
 # Defining fileds to select
-fields='$HOST $USER $DNS_USER $TYPE $TIME $DATE'
+fields='$HOST $USER $DNS_USER $SUSPENDED $TIME $DATE'
 
 case $format in
     json)   json_list ;;

+ 5 - 1
bin/v-restart-dns

@@ -34,7 +34,11 @@ if [ ! -z "$DNS_SYSTEM" ]; then
     if [ $? -ne 0 ]; then
         /etc/init.d/$DNS_SYSTEM restart >/dev/null 2>&1
         if [ $? -ne 0 ]; then
-            send_mail="$VESTA/web/inc/mail-wrapper.php"
+            if [ -e "$VESTA/web/inc/mail-wrapper.php" ]; then
+                send_mail="$VESTA/web/inc/mail-wrapper.php"
+            else
+                send_mail=$(which mail)
+            fi
             email=$(grep CONTACT $VESTA/data/users/admin/user.conf)
             email=$(echo "$email" | cut -f 2 -d "'")
             tmpfile=$(mktemp)

+ 1 - 1
bin/v-sync-dns-cluster

@@ -46,7 +46,7 @@ old_ifs="$IFS"
 IFS=$'\n'
 
 if [ -z $host ]; then
-    hosts=$(cat $VESTA/conf/dns-cluster.conf)
+    hosts=$(cat $VESTA/conf/dns-cluster.conf | grep "SUSPENDED=='no'")
     rm -f $VESTA/data/queue/dns-cluster.pipe
     touch $VESTA/data/queue/dns-cluster.pipe
     chmod 660 $VESTA/data/queue/dns-cluster.pipe

+ 47 - 0
func/remote.sh

@@ -107,3 +107,50 @@ is_dnshost_alive() {
         exit $E_NOTEXIST
     fi
 }
+
+remote_dns_health_check() {
+    # Define tmp mail vars
+    subj="DNS sync failed"
+    email=$(grep CONTACT $VESTA/data/users/admin/user.conf | cut -f 2 -d \')
+    send_mail="$VESTA/web/inc/mail-wrapper.php"
+    tmpfile=$(mktemp)
+
+    # Starting health-check
+    for str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
+
+        # Get host values
+        eval $str
+
+        # Check connection type
+        if [ -z "TYPE" ]; then
+            TYPE='api'
+        fi
+
+        # Switch on connection type
+        case $TYPE in
+            ssh) send_cmd="send_ssh_cmd" ;;
+            *)  send_cmd="send_api_cmd" ;;
+        esac
+
+        # Check host connection
+        $send_cmd v-list-sys-config
+        if [ $? -ne 0 ]; then
+            echo "$(basename $0) $*" > $tmpfile
+            echo -e "Error: $TYPE connection to $HOST failed.\n" >> $tmpfile
+            echo -n "Remote dns host has been suspended." >> $tmpfile
+            echo -n "After resolving issue run "  >> $tmpfile
+            echo -e "following commands:\n" >> $tmpfile
+            echo "v-unsuspend-remote-dns-host $HOST" >> $tmpfile
+            echo "v-sync-dns-clustert $HOST" >> $tmpfile
+            echo -e "\n\n--\nVesta Control Panel\n$(hostname)" >> $tmpfile
+            cat $tmpfile |  $send_mail -s "$subj" $email
+
+            log_event "$E_CONNECT $EVENT"
+            dconf="../../../conf/dns-cluster"
+            update_object_value "$dconf" 'HOST' "$HOST" '$SUSPENDED' 'yes'
+        fi
+
+        # Remove tmp file
+        rm -f $tmpfile
+    done
+}