1
0
mirror of https://github.com/serghey-rodin/vesta.git synced 2025-03-11 20:26:30 -07:00
vesta/bin/v-add-remote-dns-domain

92 lines
2.5 KiB
Plaintext
Raw Normal View History

2013-05-28 16:09:07 +03:00
#!/bin/bash
# info: add remote dns domain
2013-11-27 09:02:40 +02:00
# options: USER DOMAIN [FLUSH]
2013-05-28 16:09:07 +03:00
#
# The function synchronize dns domain with the remote server.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
2015-11-06 17:38:58 +02:00
# Argument definition
2013-05-28 16:09:07 +03:00
user=$1
domain=$2
2013-11-27 09:02:40 +02:00
flush=$3
2013-05-28 16:09:07 +03:00
2016-08-25 19:45:37 +03:00
2013-05-28 16:09:07 +03:00
# Includes
source $VESTA/func/main.sh
source $VESTA/func/remote.sh
source $VESTA/conf/vesta.conf
2013-05-28 16:09:07 +03:00
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
2013-11-27 09:02:40 +02:00
check_args '2' "$#" 'USER DOMAIN [FLUSH]'
is_format_valid 'user' 'domain'
2013-05-29 13:16:09 +03:00
is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
2016-08-25 19:45:37 +03:00
is_procces_running
2015-10-21 15:54:07 +03:00
remote_dns_health_check
2013-05-28 16:09:07 +03:00
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
2015-10-21 15:54:07 +03:00
# Parsing domain record
str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null)
if [ -z "$str" ]; then
2013-11-01 23:20:01 +02:00
pipe="$VESTA/data/queue/dns-cluster.pipe"
queue_str=$(grep -n "$SCRIPT $1 $2 " $pipe |cut -f1 -d: |head -n1)
2015-10-21 15:54:07 +03:00
if [ ! -z "$queue_str" ]; then
sed -i "$queue_str d" $pipe
2013-11-01 23:20:01 +02:00
fi
exit
fi
2013-05-28 16:09:07 +03:00
IFS=$'\n'
2015-10-21 15:54:07 +03:00
for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
2013-05-28 16:09:07 +03:00
2015-10-21 15:54:07 +03:00
# Parsing remote dns host parameters
eval $cluster
2015-10-21 15:54:07 +03:00
# Parsing domain parameters
eval $str
2013-05-28 16:09:07 +03:00
2015-10-21 15:54:07 +03:00
# Syncing domain data
cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
check_result $? "$HOST connection failed" $E_CONNECT
2013-05-28 16:09:07 +03:00
2015-10-21 15:54:07 +03:00
# 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
2013-05-28 16:09:07 +03:00
2015-10-21 15:54:07 +03:00
# Inserting synced records
cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
check_result $? "$HOST connection failed" $E_CONNECT
2013-05-28 16:09:07 +03:00
2015-10-21 15:54:07 +03:00
# Rebuilding dns zone
cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
check_result $? "$HOST connection failed" $E_CONNECT
done
2013-05-28 16:09:07 +03:00
2013-11-27 09:02:40 +02:00
2015-10-21 15:54:07 +03:00
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
2013-05-28 16:09:07 +03:00
2015-10-21 15:54:07 +03:00
# Updating pipe
rm -f $tmpfile
2013-05-28 16:09:07 +03:00
pipe="$VESTA/data/queue/dns-cluster.pipe"
2013-11-27 09:02:40 +02:00
str=$(grep -n "$SCRIPT $1 $2 " $pipe | cut -f1 -d: | head -n1)
2013-05-28 16:09:07 +03:00
if [ ! -z "$str" ]; then
sed -i "$str d" $pipe
fi
exit