diff --git a/bin/v-add-remote-dns-domain b/bin/v-add-remote-dns-domain index 2be01e5e..0eb33326 100755 --- a/bin/v-add-remote-dns-domain +++ b/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 diff --git a/bin/v-add-remote-dns-record b/bin/v-add-remote-dns-record index 2676fb19..d559f2fd 100755 --- a/bin/v-add-remote-dns-record +++ b/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 diff --git a/bin/v-change-remote-dns-domain-exp b/bin/v-change-remote-dns-domain-exp index cb11c729..53e5ece5 100755 --- a/bin/v-change-remote-dns-domain-exp +++ b/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 diff --git a/bin/v-change-remote-dns-domain-soa b/bin/v-change-remote-dns-domain-soa index 6b6dfb06..18765901 100755 --- a/bin/v-change-remote-dns-domain-soa +++ b/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 diff --git a/bin/v-change-remote-dns-domain-ttl b/bin/v-change-remote-dns-domain-ttl index 053a4115..680ad0c1 100755 --- a/bin/v-change-remote-dns-domain-ttl +++ b/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 diff --git a/bin/v-list-remote-dsn-hosts b/bin/v-list-remote-dns-hosts similarity index 95% rename from bin/v-list-remote-dsn-hosts rename to bin/v-list-remote-dns-hosts index 6f8c05b2..00d265fd 100755 --- a/bin/v-list-remote-dsn-hosts +++ b/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 ;; diff --git a/bin/v-restart-dns b/bin/v-restart-dns index 12778e14..87a0bf11 100755 --- a/bin/v-restart-dns +++ b/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) diff --git a/bin/v-sync-dns-cluster b/bin/v-sync-dns-cluster index 9783d88e..f563c8be 100755 --- a/bin/v-sync-dns-cluster +++ b/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 diff --git a/func/remote.sh b/func/remote.sh index be301381..08271297 100644 --- a/func/remote.sh +++ b/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 +}