vesta/bin/v-add-remote-dns-record
2013-10-24 00:10:54 +03:00

112 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# info: add remote dns domain record
# options: USER DOMAIN ID
#
# The function synchronize dns domain with the remote server.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
domain=$2
id=$3
# Includes
source $VESTA/func/main.sh
source $VESTA/func/remote.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '3' "$#" 'USER DOMAIN ID'
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
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
fi
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
old_ifs="$IFS"
IFS=$'\n'
# 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
# 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 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'
if [ $? -ne 0 ]; then
echo "Error: $TYPE connection to $HOST failed (rebuild)"
log_event "$E_CONNECT $EVENT"
exit $E_CONNECT
fi
fi
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 #
#----------------------------------------------------------#
exit