From bdc8111b0692f396e338bd83fa2669278165568e Mon Sep 17 00:00:00 2001 From: Serghey Rodin Date: Wed, 21 Oct 2015 15:54:07 +0300 Subject: [PATCH] Fix SERIAL sync in DNS cluster --- bin/v-add-dns-domain | 62 +++++++++--- bin/v-add-dns-record | 4 +- bin/v-add-remote-dns-domain | 111 +++++++-------------- bin/v-add-remote-dns-host | 45 ++++----- bin/v-add-remote-dns-record | 96 +++++++----------- bin/v-change-remote-dns-domain-exp | 71 ++++---------- bin/v-change-remote-dns-domain-soa | 76 ++++----------- bin/v-change-remote-dns-domain-ttl | 88 ++++------------- bin/v-delete-remote-dns-domain | 79 ++++----------- bin/v-delete-remote-dns-domains | 87 ++++------------- bin/v-delete-remote-dns-host | 18 +--- bin/v-delete-remote-dns-record | 76 +++++---------- bin/v-insert-dns-domain | 5 +- bin/v-sync-dns-cluster | 150 +++++++---------------------- 14 files changed, 298 insertions(+), 670 deletions(-) diff --git a/bin/v-add-dns-domain b/bin/v-add-dns-domain index 5f18daa18..c33602998 100755 --- a/bin/v-add-dns-domain +++ b/bin/v-add-dns-domain @@ -1,6 +1,6 @@ #!/bin/bash # info: add dns domain -# options: USER DOMAIN IP [NS1] [NS2] [NS3] [NS4] [RESTART] +# options: USER DOMAIN IP [NS1] [NS2] [NS3] [..] [NS8] [RESTART] # # The function adds DNS zone with records defined in the template. If the exp # argument isn't stated, the expiration date value will be set to next year. @@ -24,7 +24,11 @@ ns1=$4 ns2=$5 ns3=$6 ns4=$7 -restart=$8 +ns5=$8 +ns6=$9 +ns7=${10} +ns8=${11} +restart=${12} # Includes source $VESTA/func/main.sh @@ -36,14 +40,13 @@ source $VESTA/conf/vesta.conf # Verifications # #----------------------------------------------------------# -check_args '3' "$#" 'USER DOMAIN IP [NS1] [NS2] [NS3] [NS4]' +check_args '3' "$#" 'USER DOMAIN IP [NS1] [NS2] [NS3] [..] [NS8] [RESTART]' validate_format 'user' 'domain' 'ip' is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM' is_object_valid 'user' 'USER' "$user" is_object_unsuspended 'user' 'USER' "$user" is_domain_new 'dns' is_package_full 'DNS_DOMAINS' - template=$(get_user_value '$DNS_TEMPLATE') is_dns_template_valid @@ -64,6 +67,23 @@ if [ ! -z "$ns4" ]; then ns4=$(echo $7 | sed -e 's/\.*$//g' -e 's/^\.*//g') validate_format 'ns4' fi +if [ ! -z "$ns5" ]; then + ns5=$(echo $8 | sed -e 's/\.*$//g' -e 's/^\.*//g') + validate_format 'ns5' +fi +if [ ! -z "$ns6" ]; then + ns6=$(echo $9 | sed -e 's/\.*$//g' -e 's/^\.*//g') + validate_format 'ns6' +fi +if [ ! -z "$ns7" ]; then + ns7=$(echo ${10} | sed -e 's/\.*$//g' -e 's/^\.*//g') + validate_format 'ns7' +fi + +if [ ! -z "$ns8" ]; then + ns8=$(echo ${11} | sed -e 's/\.*$//g' -e 's/^\.*//g') + validate_format 'ns8' +fi #----------------------------------------------------------# @@ -89,13 +109,25 @@ template_data=$(cat $DNSTPL/$template.tpl) # Deleting unused nameservers if [ -z "$ns3" ]; then - template_data=$(echo "$template_data" | grep -v %ns3%) + template_data=$(echo "$template_data" |grep -v %ns3%) fi if [ -z "$ns4" ]; then - template_data=$(echo "$template_data" | grep -v %ns4%) + template_data=$(echo "$template_data" |grep -v %ns4%) +fi +if [ -z "$ns5" ]; then + template_data=$(echo "$template_data" |grep -v %ns5%) +fi +if [ -z "$ns6" ]; then + template_data=$(echo "$template_data" |grep -v %ns6%) +fi +if [ -z "$ns7" ]; then + template_data=$(echo "$template_data" |grep -v %ns7%) +fi +if [ -z "$ns8" ]; then + template_data=$(echo "$template_data" |grep -v %ns8%) fi -# Add dns zone to the user config +# Adding dns zone to the user config echo "$template_data" |\ sed -e "s/%ip%/$ip/g" \ -e "s/%domain_idn%/$domain_idn/g" \ @@ -104,6 +136,10 @@ echo "$template_data" |\ -e "s/%ns2%/$ns2/g" \ -e "s/%ns3%/$ns3/g" \ -e "s/%ns4%/$ns4/g" \ + -e "s/%ns5%/$ns5/g" \ + -e "s/%ns6%/$ns6/g" \ + -e "s/%ns7%/$ns7/g" \ + -e "s/%ns8%/$ns8/g" \ -e "s/%time%/$TIME/g" \ -e "s/%date%/$DATE/g" > $USER_DATA/dns/$domain.conf @@ -118,7 +154,7 @@ dns_rec="$dns_rec SUSPENDED='no' TIME='$TIME' DATE='$DATE'" echo "$dns_rec" >> $USER_DATA/dns.conf chmod 660 $USER_DATA/dns.conf -# Create system configs +# Creating system configs if [[ "$DNS_SYSTEM" =~ named|bind ]]; then if [ -e '/etc/named.conf' ]; then dns_conf='/etc/named.conf' @@ -136,9 +172,9 @@ if [[ "$DNS_SYSTEM" =~ named|bind ]]; then # Updating domain dns zone update_domain_zone - # Set permissions - chmod 640 $conf - chown root:$dns_group $conf + # Changing permissions + chmod 640 $HOMEDIR/$user/conf/dns/$domain.db + chown root:$dns_group $HOMEDIR/$user/conf/dns/$domain.db fi # Updating dns-cluster queue @@ -159,9 +195,7 @@ increase_user_value "$user" '$U_DNS_RECORDS' "$records" # Restart named if [ "$restart" != 'no' ]; then $BIN/v-restart-dns - if [ $? -ne 0 ]; then - exit $E_RESTART - fi + check_result $? "DNS restart failed" fi # Logging diff --git a/bin/v-add-dns-record b/bin/v-add-dns-record index 928b5c48d..af1744895 100755 --- a/bin/v-add-dns-record +++ b/bin/v-add-dns-record @@ -109,9 +109,7 @@ increase_user_value "$user" '$U_DNS_RECORDS' # Restart named if [ "$restart" != 'no' ]; then $BIN/v-restart-dns - if [ $? -ne 0 ]; then - exit $E_RESTART - fi + check_result $? $E_RESTART 'dns failed to restart' fi # Logging diff --git a/bin/v-add-remote-dns-domain b/bin/v-add-remote-dns-domain index e6a340484..e84a0e3dc 100755 --- a/bin/v-add-remote-dns-domain +++ b/bin/v-add-remote-dns-domain @@ -27,101 +27,64 @@ source $VESTA/conf/vesta.conf check_args '2' "$#" 'USER DOMAIN [FLUSH]' validate_format 'user' 'domain' is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then + check_result $E_EXISTS "another sync process already running" fi +remote_dns_health_check #----------------------------------------------------------# # Action # #----------------------------------------------------------# -# Check domain existance -check_local_domain=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null) -if [ -z "$check_local_domain" ]; then +# Parsing domain record +str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null) +if [ -z "$str" ]; then pipe="$VESTA/data/queue/dns-cluster.pipe" - str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1) - if [ ! -z "$str" ]; then - sed -i "$str d" $pipe + queue_str=$(grep -n "$SCRIPT $1 $2 no$" $pipe |cut -f1 -d: |head -n1) + if [ ! -z "$queue_str" ]; then + sed -i "$queue_str d" $pipe fi exit fi -old_ifs="$IFS" IFS=$'\n' +for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do -# Check remote dns nodes -remote_dns_health_check + # Parsing remote dns host parameters + eval $cluster -search_str=$(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf) -for cluster_str in $search_str; do - - # Get host values - eval $cluster_str - - # Check connection type - if [ -z "TYPE" ]; then - 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 dns exceptions - if [ -z "$DNS_CLUSTER_IGNORE" ]; then - DNS_CLUSTER_IGNORE='dns-cluster' - fi - - # Check flush parameters - - # Sync domain - str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) + # Parsing domain parameters eval $str - $send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME "$flush" 'no' - if [ $? -eq 0 ]; then - # Sync records - if [ "$TYPE" = 'ssh' ]; then - tmp=$(mktemp -u) - scp_cmd $USER_DATA/dns/$DOMAIN.conf $tmp - $send_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp 'no' - else - for str in $(cat $USER_DATA/dns/$DOMAIN.conf); do - str=$(echo "$str" | sed 's/"/\\"/g') - $send_cmd v-insert-dns-record $DNS_USER $DOMAIN "$str" - done - fi + # Syncing domain data + cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no' + check_result $? "$HOST connection failed" $E_CONNECT - # Rebuild dns zone - $send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled' 'no' - if [ $? -ne 0 ]; then - echo "Error: $TYPE connection to $HOST failed" - log_event "$E_CONNECT $EVENT" - exit $E_CONNECT - fi - fi + # Syncing domain records + tmp_file="/tmp/vst-sync.$DOMAIN" + cluster_file $USER_DATA/dns/$DOMAIN.conf $tmp_file + check_result $? "$HOST connection failed" $E_CONNECT + # Inserting synced records + cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no' + check_result $? "$HOST connection failed" $E_CONNECT + + # Rebuilding dns zone + cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no' + check_result $? "$HOST connection failed" $E_CONNECT done -# Update pipe + + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Updating pipe rm -f $tmpfile pipe="$VESTA/data/queue/dns-cluster.pipe" str=$(grep -n "$SCRIPT $1 $2 " $pipe | cut -f1 -d: | head -n1) @@ -129,8 +92,4 @@ if [ ! -z "$str" ]; then sed -i "$str d" $pipe fi -#----------------------------------------------------------# -# Vesta # -#----------------------------------------------------------# - exit diff --git a/bin/v-add-remote-dns-host b/bin/v-add-remote-dns-host index 1ca8b0034..c004ee316 100755 --- a/bin/v-add-remote-dns-host +++ b/bin/v-add-remote-dns-host @@ -11,10 +11,15 @@ # Argument defenition host=$1 +HOST=$host port=$2 +PORT=$port user=$3 -password=$4 +USER=$user +password=$4; HIDE=4 +PASSWORD=$password type=${5-api} +TYPE="$type" dns_user=${6-dns-cluster} DNS_USER=$dns_user @@ -23,10 +28,6 @@ source $VESTA/func/main.sh source $VESTA/func/remote.sh source $VESTA/conf/vesta.conf -# Hiding passwords -A4='******' -EVENT="$DATE $TIME $SCRIPT $A1 $A2 $A3 $A4 $A5 $A6 $A7 $A8 $A9" - #----------------------------------------------------------# # Verifications # @@ -61,36 +62,26 @@ else sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $VESTA/conf/vesta.conf fi -# Enabling restart queue -HOST=$host -PORT=$port -USER=$user -PASSWORD=$password -case $type in - ssh) send_cmd="send_ssh_cmd" ;; - *) send_cmd="send_api_cmd" ;; -esac -$send_cmd v-add-cron-restart-job +# Enabling remote dns-cluster queue +cluster_cmd v-add-cron-restart-job +check_result $? "$HOST connection failed" $E_CONNECT -# Sync current zones +# Syncing all domains $BIN/v-sync-dns-cluster $host -return_code=$? -if [ "$return_code" -ne 0 ]; then - exit $return_code -fi - -# Add dns-cluster cron job -cmd="sudo /usr/local/vesta/bin/v-update-sys-queue dns-cluster" -check_cron=$(grep "$cmd" $VESTA/data/users/admin/cron.conf 2> /dev/null) -if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then - $BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd" -fi +check_result $? "$HOST sync failed" $E_CONNECT #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# +# Adding local dns-cluster cron job +cmd="sudo /usr/local/vesta/bin/v-update-sys-queue dns-cluster" +check_cron=$(grep "$cmd" $VESTA/data/users/admin/cron.conf 2> /dev/null) +if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then + $BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd" +fi + # Logging log_event "$OK" "$EVENT" diff --git a/bin/v-add-remote-dns-record b/bin/v-add-remote-dns-record index ecd816810..f1a7fee59 100755 --- a/bin/v-add-remote-dns-record +++ b/bin/v-add-remote-dns-record @@ -29,86 +29,62 @@ validate_format 'user' 'domain' 'id' is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' is_object_valid 'user' 'USER' "$user" is_object_valid 'dns' 'DOMAIN' "$domain" -is_object_valid "dns/$domain" 'ID' "$id" - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then + check_result $E_EXISTS "another sync process already running" fi +remote_dns_health_check #----------------------------------------------------------# # Action # #----------------------------------------------------------# -old_ifs="$IFS" +# Parsing record +str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf) +if [ -z "$str" ]; then + pipe="$VESTA/data/queue/dns-cluster.pipe" + queue_str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) + if [ ! -z "$queue_str" ]; then + sed -i "$queue_str d" $pipe + fi + exit +fi + IFS=$'\n' +for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do -# Check remote dns nodes -remote_dns_health_check + # Parsing remote host parameters + eval $cluster -for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do - # Get host values - eval $cluster_str + # Syncing serial + str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) + cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no' + check_result $? "$HOST connection failed (soa sync)" $E_CONNECT - # Check connection type - if [ -z "TYPE" ]; then - TYPE='api' - fi + # Syncing record + str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf | sed 's/"/\\"/g') + cluster_cmd v-insert-dns-record $DNS_USER $domain "$str" 'no' + check_result $? "$HOST connection failed (record sync)" $E_CONNECT - # Switch on connection type - case $TYPE in - ssh) send_cmd="send_ssh_cmd" ;; - *) send_cmd="send_api_cmd" ;; - esac - - # Check recipient dns user - if [ -z "$DNS_USER" ]; then - DNS_USER='dns-cluster' - fi - - # Check dns exceptions - if [ -z "$DNS_CLUSTER_IGNORE" ]; then - DNS_CLUSTER_IGNORE='dns-cluster' - fi - - # Sync SOA - $send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no' - - # Sync record - str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf) - str=$(echo "$str" | sed 's/"/\\"/g') - $send_cmd v-insert-dns-record $DNS_USER $domain "$str" 'no' - if [ $? -eq 0 ]; then - # Rebuild dns zone - $send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled' 'no' - if [ $? -ne 0 ]; then - echo "Error: $TYPE connection to $HOST failed (rebuild)" - log_event "$E_CONNECT $EVENT" - exit $E_CONNECT - fi - fi + # Rebuilding dns zone + cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no' + check_result $? "$HOST connection failed (rebuild)" $E_CONNECT done -# Update pipe -pipe="$VESTA/data/queue/dns-cluster.pipe" -str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) -if [ ! -z "$str" ]; then - sed -i "$str d" $pipe -fi - #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# +# Updating pipe +pipe="$VESTA/data/queue/dns-cluster.pipe" +str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) +if [ ! -z "$str" ]; then + sed -i "$str d" $pipe +fi + exit diff --git a/bin/v-change-remote-dns-domain-exp b/bin/v-change-remote-dns-domain-exp index 9cd4a37bd..885f15aef 100755 --- a/bin/v-change-remote-dns-domain-exp +++ b/bin/v-change-remote-dns-domain-exp @@ -28,79 +28,42 @@ validate_format 'user' 'domain' is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' is_object_valid 'user' 'USER' "$user" is_object_valid 'dns' 'DOMAIN' "$domain" - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then + check_result $E_EXISTS "another sync process already running" fi +remote_dns_health_check #----------------------------------------------------------# # Action # #----------------------------------------------------------# -old_ifs="$IFS" IFS=$'\n' +for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do -# Check remote dns nodes -remote_dns_health_check + # Parsing remote host parameters + eval $cluster -for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do - - # Get host values - eval $cluster_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 recipient dns user - if [ -z "$DNS_USER" ]; then - DNS_USER='dns-cluster' - fi - - # Check dns exceptions - if [ -z "$DNS_CLUSTER_IGNORE" ]; then - DNS_CLUSTER_IGNORE='dns-cluster' - fi - - # Sync domain + # Syncing domain 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 + cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no' + check_result $? "$HOST connection failed (exp insert)" $E_CONNECT done -# Update pipe -pipe="$VESTA/data/queue/dns-cluster.pipe" -str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) -if [ ! -z "$str" ]; then - sed -i "$str d" $pipe -fi - #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# +# Updating pipe +pipe="$VESTA/data/queue/dns-cluster.pipe" +str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) +if [ ! -z "$str" ]; then + sed -i "$str d" $pipe +fi + exit diff --git a/bin/v-change-remote-dns-domain-soa b/bin/v-change-remote-dns-domain-soa index 99734e756..4adf2a4d7 100755 --- a/bin/v-change-remote-dns-domain-soa +++ b/bin/v-change-remote-dns-domain-soa @@ -28,82 +28,46 @@ validate_format 'user' 'domain' is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' is_object_valid 'user' 'USER' "$user" is_object_valid 'dns' 'DOMAIN' "$domain" - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result 1 $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $VESTA/bin/$SCRIPT |wc -l)" -gt 2 ]; then + check_result 1 $E_EXISTS "another sync process already running" fi +remote_dns_health_check #----------------------------------------------------------# # Action # #----------------------------------------------------------# -old_ifs="$IFS" IFS=$'\n' +for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do -# Check remote dns nodes -remote_dns_health_check + # Parsing remote host parameters + eval $cluster -for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do - - # Get host values - eval $cluster_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 recipient dns user - if [ -z "$DNS_USER" ]; then - DNS_USER='dns-cluster' - fi - - # Check dns exceptions - if [ -z "$DNS_CLUSTER_IGNORE" ]; then - DNS_CLUSTER_IGNORE='dns-cluster' - fi - - # Sync domain + # Syncing SOA str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) - eval $str - $send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no' + cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no' + check_result $? "$HOST connection failed (sync)" $E_CONNECT - # Rebuild dns zone - $send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled' 'no' - if [ $? -ne 0 ]; then - echo "Error: $TYPE connection to $HOST failed (rebuild)" - log_event "$E_CONNECT $EVENT" - exit $E_CONNECT - fi + # Rebuilding dns zone + cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no' + check_result $? "$HOST connection failed (rebuild)" $E_CONNECT done -# Update pipe -pipe="$VESTA/data/queue/dns-cluster.pipe" -str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) -if [ ! -z "$str" ]; then - sed -i "$str d" $pipe -fi - #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# +# Updating pipe +pipe="$VESTA/data/queue/dns-cluster.pipe" +str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) +if [ ! -z "$str" ]; then + sed -i "$str d" $pipe +fi + exit diff --git a/bin/v-change-remote-dns-domain-ttl b/bin/v-change-remote-dns-domain-ttl index 25ff0e6ad..a03664d79 100755 --- a/bin/v-change-remote-dns-domain-ttl +++ b/bin/v-change-remote-dns-domain-ttl @@ -28,96 +28,46 @@ validate_format 'user' 'domain' is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' is_object_valid 'user' 'USER' "$user" is_object_valid 'dns' 'DOMAIN' "$domain" - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then + check_result $E_EXISTS "another sync process already running" fi +remote_dns_health_check #----------------------------------------------------------# # Action # #----------------------------------------------------------# -old_ifs="$IFS" IFS=$'\n' +for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do -# Check remote dns nodes -remote_dns_health_check + # Parsing remote host parameters + eval $cluster -# Starting cluster loop -for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do - - # Get host values - eval $cluster_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 "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' - fi - - # Sync domain + # Syncing TTL str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) - eval $str - $send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no' + cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no' + check_result $? "$HOST connection failed (sync)" $E_CONNECT - # Rebuild dns zone - $send_cmd v-rebuild-dns-domain $DNS_USER $domain 'scheduled' 'no' - if [ $? -ne 0 ]; then - echo "Error: $TYPE connection to $HOST failed (rebuild)" - log_event "$E_CONNECT $EVENT" - exit $E_CONNECT - fi + # Rebuilding dns zone + cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no' + check_result $? "$HOST connection failed (rebuild)" $E_CONNECT done -# Update pipe + +#----------------------------------------------------------# +# Vesta # +#----------------------------------------------------------# + +# Updating pipe pipe="$VESTA/data/queue/dns-cluster.pipe" str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) if [ ! -z "$str" ]; then sed -i "$str d" $pipe fi -#----------------------------------------------------------# -# Vesta # -#----------------------------------------------------------# - exit diff --git a/bin/v-delete-remote-dns-domain b/bin/v-delete-remote-dns-domain index 1ba782dbc..bbe3d9290 100755 --- a/bin/v-delete-remote-dns-domain +++ b/bin/v-delete-remote-dns-domain @@ -26,84 +26,45 @@ source $VESTA/conf/vesta.conf check_args '2' "$#" 'USER DOMAIN' validate_format 'user' 'domain' is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then + check_result $E_EXISTS "another sync process already running" fi +remote_dns_health_check #----------------------------------------------------------# # Action # #----------------------------------------------------------# -old_ifs="$IFS" -IFS=$'\n' - # Starting cluster loop -for cluster_str in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do +IFS=$'\n' +for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do - # Get host values - eval $cluster_str + # Parsing remote host parameters + eval $cluster - # Check connection type - if [ -z "TYPE" ]; then - TYPE='api' + # Syncing domain + cluster_cmd v-delete-dns-domain $DNS_USER $domain 'yes' + rc=$? + if [ "$rc" -ne 0 ] && [ $rc -ne 3 ]; then + check_result $rc "$HOST connection failed (sync)" $E_CONNECT 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' - fi - - # Sync domain - $send_cmd v-delete-dns-domain $DNS_USER $domain 'scheduled' - done -# Update pipe -pipe="$VESTA/data/queue/dns-cluster.pipe" -str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1) -if [ ! -z "$str" ]; then - sed -i "$str d" $pipe -fi - #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# +# Updating pipe +pipe="$VESTA/data/queue/dns-cluster.pipe" +str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1) +if [ ! -z "$str" ]; then + sed -i "$str d" $pipe +fi + exit diff --git a/bin/v-delete-remote-dns-domains b/bin/v-delete-remote-dns-domains index c2e2300f5..bb8c9b7ca 100755 --- a/bin/v-delete-remote-dns-domains +++ b/bin/v-delete-remote-dns-domains @@ -22,26 +22,19 @@ source $VESTA/conf/vesta.conf #----------------------------------------------------------# is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then + check_result $E_EXISTS "another sync process already running" fi +remote_dns_health_check #----------------------------------------------------------# # Action # #----------------------------------------------------------# -old_ifs="$IFS" IFS=$'\n' if [ -z $host ]; then @@ -51,65 +44,18 @@ else fi # Starting cluster loop -for cluster_str in $hosts; do +for cluster in $hosts; do - # Get host values - eval $cluster_str + # Parsing remote host parameters + eval $cluster - # Check connection type - if [ -z "TYPE" ]; then - TYPE='api' - fi + # Deleting source records + cluster_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME 'no' + check_result $? "$HOST connection failed (cleanup)" $E_CONNECT - # Print hostname - if [ ! -z "$verbose" ]; then - echo "HOSTNAME: $HOSTNAME" - echo "TYPE: $TYPE" - 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 - if [ ! -z "$verbose" ]; then - echo "DNS_USER: $DNS_USER" - 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 - - # Clean source records - $send_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME 'no' - if [ $? -ne 0 ]; then - echo "Error: $TYPE connection to $HOST failed (cleanup)" - log_event "$E_CONNECT $EVENT" - exit $E_CONNECT - fi - - # Rebuild dns zones - $send_cmd v-rebuild-dns-domains $DNS_USER 'scheduled' - if [ $? -ne 0 ]; then - echo "Error: $TYPE connection to $HOST failed (rebuild)" - log_event "$E_CONNECT $EVENT" - exit $E_CONNECT - fi + # Rebuilding dns zones + $send_cmd v-rebuild-dns-domains $DNS_USER 'yes' + check_result $? "$HOST connection failed (rebuild)" $E_CONNECT done @@ -118,4 +64,11 @@ done # Vesta # #----------------------------------------------------------# +# Updating pipe +pipe="$VESTA/data/queue/dns-cluster.pipe" +str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1) +if [ ! -z "$str" ]; then + sed -i "$str d" $pipe +fi + exit diff --git a/bin/v-delete-remote-dns-host b/bin/v-delete-remote-dns-host index e82cad688..344ece6df 100755 --- a/bin/v-delete-remote-dns-host +++ b/bin/v-delete-remote-dns-host @@ -32,25 +32,13 @@ is_object_valid "../../conf/dns-cluster" 'HOST' "$host" # Action # #----------------------------------------------------------# -eval $(grep $host $VESTA/conf/dns-cluster.conf) -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 [ $? -eq 0 ]; then - # Deleting domains - $BIN/v-delete-remote-dns-domains $host >>/dev/null 2>&1 - $send_cmd v-add-cron-restart-job -fi +# Deleting remote domains +$BIN/v-delete-remote-dns-domains $host >>/dev/null 2>&1 # Deleting server sed -i "/HOST='$host' /d" $VESTA/conf/dns-cluster.conf -# Delete DNS_CLUSTER key +# Deleting DNS_CLUSTER key check_cluster=$(grep HOST $VESTA/conf/dns-cluster.conf |wc -l) if [ "$check_cluster" -eq '0' ]; then rm -f $VESTA/conf/dns-cluster.conf diff --git a/bin/v-delete-remote-dns-record b/bin/v-delete-remote-dns-record index 29102f6e6..0c09d68cc 100755 --- a/bin/v-delete-remote-dns-record +++ b/bin/v-delete-remote-dns-record @@ -27,79 +27,53 @@ source $VESTA/conf/vesta.conf check_args '3' "$#" 'USER DOMAIN ID' validate_format 'user' 'domain' 'id' is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then + check_result $E_EXISTS "another sync process already running" fi +remote_dns_health_check #----------------------------------------------------------# # Action # #----------------------------------------------------------# -old_ifs="$IFS" -IFS=$'\n' # Starting cluster loop -for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do +IFS=$'\n' +for cluster in $(cat $VESTA/conf/dns-cluster.conf); do - # Get host values - eval $cluster_str + # Parsing remote host parameters + eval $cluster - # 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 "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 + # Syncing serial + str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf) + cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no' + check_result $? "$HOST connection failed (soa sync)" $E_CONNECT # Sync domain - $send_cmd v-delete-dns-record $DNS_USER $domain $id 'scheduled' + cluster_cmd v-delete-dns-record $DNS_USER $domain $id 'no' + check_result $? "$HOST connection failed (rebuild)" $E_CONNECT + + # Rebuilding dns zone + cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no' + check_result $? "$HOST connection failed (rebuild)" $E_CONNECT done -# Update pipe -pipe="$VESTA/data/queue/dns-cluster.pipe" -str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) -if [ ! -z "$str" ]; then - sed -i "$str d" $pipe -fi #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# +# Updating pipe +pipe="$VESTA/data/queue/dns-cluster.pipe" +str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1) +if [ ! -z "$str" ]; then + sed -i "$str d" $pipe +fi + exit diff --git a/bin/v-insert-dns-domain b/bin/v-insert-dns-domain index be98ac3ff..fcd548ae7 100755 --- a/bin/v-insert-dns-domain +++ b/bin/v-insert-dns-domain @@ -26,7 +26,7 @@ source $VESTA/conf/vesta.conf # Verifications # #----------------------------------------------------------# -check_args '2' "$#" 'USER DATA [SRC] [RESTART]' +check_args '2' "$#" 'USER DATA [SRC] [FLUSH] [RESTART]' validate_format 'user' 'data' is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM' is_object_valid 'user' 'USER' "$user" @@ -47,11 +47,10 @@ if [ "$flush" = 'records' ]; then rm -f $USER_DATA/dns/$DOMAIN.conf touch $USER_DATA/dns/$DOMAIN.conf chmod 660 $USER_DATA/dns/$DOMAIN.conf - exit fi # Flush domain -if [ "$flush" = 'domain' ]; then +if [ "$flush" ! = 'no' ]; then sed -i "/DOMAIN='$DOMAIN'/d" $USER_DATA/dns.conf 2> /dev/null fi diff --git a/bin/v-sync-dns-cluster b/bin/v-sync-dns-cluster index ac0045184..d4a1e00db 100755 --- a/bin/v-sync-dns-cluster +++ b/bin/v-sync-dns-cluster @@ -10,7 +10,6 @@ # Argument defenition host=$1 -verbose=$2 # Includes source $VESTA/func/main.sh @@ -23,146 +22,60 @@ source $VESTA/conf/vesta.conf #----------------------------------------------------------# is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER' - if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then - echo "Error: dns-cluster.conf doesn't exist" - log_event "$E_NOTEXIST $EVENT" - exit $E_NOTEXIST + check_result $E_NOTEXIST "dns-cluster.conf doesn't exist" fi - -number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l) -if [ "$number_of_proc" -gt 2 ]; then - echo "Error: another sync process already exists" - log_event "$E_EXISTS $EVENT" - exit $E_EXISTS +if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then + check_result $E_EXISTS "another sync process already running" fi +remote_dns_health_check 'no_email' #----------------------------------------------------------# # Action # #----------------------------------------------------------# -old_ifs="$IFS" +# Selecting remote hosts IFS=$'\n' - if [ -z $host ]; then - 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 + hosts=$(cat $VESTA/conf/dns-cluster.conf |grep "SUSPENDED='no'") else hosts=$(grep "HOST='$host'" $VESTA/conf/dns-cluster.conf) fi # Starting cluster loop -for cluster_str in $hosts; do +for cluster in $hosts; do - # Get host values - eval $cluster_str + # Parsing host values + eval $cluster - # Check connection type - if [ -z "TYPE" ]; then - TYPE='api' - fi + # Wiping remote domains + cluster_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME no + check_result $? "$HOST connection failed" $E_CONNECT - # Print hostname - if [ ! -z "$verbose" ]; then - echo "HOSTNAME: $HOSTNAME" - echo "TYPE: $TYPE" - 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 - if [ ! -z "$verbose" ]; then - echo "DNS_USER: $DNS_USER" - 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' - fi - - # Create userlist - user_list=$(ls $VESTA/data/users) - for exception in $(echo -e "${DNS_CLUSTER_IGNORE//,/\n}"); do - user_list=$(echo "$user_list" | grep -v "^$exception$") - done - - # Clean source records - if [ ! -z "$verbose" ]; then - echo "STATUS: Wiping dns domains" - fi - $send_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME no - if [ $? -ne 0 ]; then - echo "Error: $TYPE connection to $HOST failed (cleanup)" - log_event "$E_CONNECT $EVENT" - exit $E_CONNECT - fi - - # Start user loop + # Syncing user domains + user_list=$(ls $VESTA/data/users |grep -v "dns-cluster") for user in $user_list; do - - # Sync domain for str in $(cat $VESTA/data/users/$user/dns.conf); do - eval $str - if [ ! -z "$verbose" ]; then - echo "DOMAIN: $DOMAIN index" - fi - $send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME - if [ $? -eq 0 ]; then - if [ ! -z "$verbose" ]; then - echo "DOMAIN: $DOMAIN records" - fi - # Sync record - if [ "$TYPE" = 'ssh' ]; then - tmp=$(mktemp -u) - scp_cmd $USER_DATA/$user/dns/$DOMAIN.conf $tmp - $send_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp - else - for str in $(cat $USER_DATA/$user/dns/$DOMAIN.conf); do - str=$(echo "$str" | sed 's/"/\\"/g') - $send_cmd v-insert-dns-record \ - $DNS_USER $DOMAIN "$str" - done - fi - else - if [ ! -z "$verbose" ]; then - echo "DOMAIN: $DOMAIN skiping records (not uniq)" - fi - fi + # Syncing domain index + eval $str + cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME ' ' no + check_result $? "$HOST connection failed" $E_CONNECT + + # Syncing domain records + tmp_file="/tmp/vst-sync.$DOMAIN" + cluster_file $USER_DATA/$user/dns/$DOMAIN.conf $tmp_file + check_result $? "$HOST connection failed" $E_CONNECT + + cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no' + check_result $? "$HOST connection failed" $E_CONNECT done done - # Rebuild dns zones - $send_cmd v-rebuild-dns-domains $DNS_USER - if [ $? -ne 0 ]; then - echo "Error: $TYPE connection to $HOST failed (rebuild)" - log_event "$E_CONNECT $EVENT" - exit $E_CONNECT - fi + # Rebuilding dns zones + cluster_cmd v-rebuild-dns-domains $DNS_USER + check_result $? "$TYPE connection to $HOST failed" $E_CONNECT done @@ -171,4 +84,9 @@ done # Vesta # #----------------------------------------------------------# +# Flushing dns-cluster queue +rm -f $VESTA/data/queue/dns-cluster.pipe +touch $VESTA/data/queue/dns-cluster.pipe +chmod 660 $VESTA/data/queue/dns-cluster.pipe + exit