| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #!/bin/bash
- # info: add new remote dns host
- # options: HOST PORT USER PASSWORD [TYPE] [DNS_USER]
- #
- # The function adds remote dns server to the dns cluster.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument definition
- host=$1
- HOST=$host
- port=$2
- PORT=$port
- user=$3
- USER=$user
- password=$4; HIDE=4
- PASSWORD=$password
- type=${5-api}
- TYPE="$type"
- dns_user=${6-dns-cluster}
- DNS_USER=$dns_user
- # Includes
- source $VESTA/func/main.sh
- source $VESTA/func/remote.sh
- source $VESTA/conf/vesta.conf
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- args_usage='HOST PORT USER PASSWORD [TYPE] [DNS_USER]'
- check_args '4' "$#" "$args_usage"
- is_format_valid 'host' 'port' 'user' 'type' 'dns_user'
- is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
- is_password_valid
- is_dnshost_new
- is_dnshost_alive
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Generating timestamp
- time_n_date=$(date +'%T %F')
- time=$(echo "$time_n_date" |cut -f 1 -d \ )
- date=$(echo "$time_n_date" |cut -f 2 -d \ )
- # Concatentating dns host string
- str="HOST='$host' PORT='$port' USER='$user' PASSWORD='$password'"
- str="$str DNS_USER='$dns_user' TYPE='$type' SUSPENDED='no'"
- str="$str TIME='$time' DATE='$date'"
- # Adding host to dns-cluster.conf
- echo "$str" >> $VESTA/conf/dns-cluster.conf
- chmod 660 $VESTA/conf/dns-cluster.conf
- # Enabling DNS_CLUSTER
- if [ -z "$(grep DNS_CLUSTER $VESTA/conf/vesta.conf)" ]; then
- sed -i "s/^STATS_/DNS_CLUSTER='yes'\nSTATS_/g" $VESTA/conf/vesta.conf
- else
- sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $VESTA/conf/vesta.conf
- fi
- # Enabling remote dns-cluster queue
- cluster_cmd v-add-cron-restart-job
- check_result $? "$HOST connection failed" $E_CONNECT
- # Syncing all domains
- $BIN/v-sync-dns-cluster $host
- 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" "$ARGUMENTS"
- exit
|