| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/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"
- validate_format 'host' 'port' 'user' 'type' 'dns_user'
- is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
- is_password_valid
- is_dnshost_new
- is_dnshost_alive
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # 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" "$EVENT"
- exit
|