v-add-remote-dns-host 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. # info: add new remote dns host
  3. # options: HOST PORT USER PASSWORD [TYPE] [DNS_USER]
  4. #
  5. # The function adds remote dns server to the dns cluster.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. host=$1
  11. HOST=$host
  12. port=$2
  13. PORT=$port
  14. user=$3
  15. USER=$user
  16. password=$4; HIDE=4
  17. PASSWORD=$password
  18. type=${5-api}
  19. TYPE="$type"
  20. dns_user=${6-dns-cluster}
  21. DNS_USER=$dns_user
  22. # Includes
  23. source $VESTA/func/main.sh
  24. source $VESTA/func/remote.sh
  25. source $VESTA/conf/vesta.conf
  26. #----------------------------------------------------------#
  27. # Verifications #
  28. #----------------------------------------------------------#
  29. args_usage='HOST PORT USER PASSWORD [TYPE] [DNS_USER]'
  30. check_args '4' "$#" "$args_usage"
  31. is_format_valid 'host' 'port' 'user' 'type' 'dns_user'
  32. is_system_enabled "$DNS_SYSTEM" 'DNS_SYSTEM'
  33. is_password_valid
  34. is_dnshost_new
  35. is_dnshost_alive
  36. #----------------------------------------------------------#
  37. # Action #
  38. #----------------------------------------------------------#
  39. # Generating timestamp
  40. time_n_date=$(date +'%T %F')
  41. time=$(echo "$time_n_date" |cut -f 1 -d \ )
  42. date=$(echo "$time_n_date" |cut -f 2 -d \ )
  43. # Concatentating dns host string
  44. str="HOST='$host' PORT='$port' USER='$user' PASSWORD='$password'"
  45. str="$str DNS_USER='$dns_user' TYPE='$type' SUSPENDED='no'"
  46. str="$str TIME='$time' DATE='$date'"
  47. # Adding host to dns-cluster.conf
  48. echo "$str" >> $VESTA/conf/dns-cluster.conf
  49. chmod 660 $VESTA/conf/dns-cluster.conf
  50. # Enabling DNS_CLUSTER
  51. if [ -z "$(grep DNS_CLUSTER $VESTA/conf/vesta.conf)" ]; then
  52. sed -i "s/^STATS_/DNS_CLUSTER='yes'\nSTATS_/g" $VESTA/conf/vesta.conf
  53. else
  54. sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $VESTA/conf/vesta.conf
  55. fi
  56. # Enabling remote dns-cluster queue
  57. cluster_cmd v-add-cron-restart-job
  58. check_result $? "$HOST connection failed" $E_CONNECT
  59. # Syncing all domains
  60. $BIN/v-sync-dns-cluster $host
  61. check_result $? "$HOST sync failed" $E_CONNECT
  62. #----------------------------------------------------------#
  63. # Vesta #
  64. #----------------------------------------------------------#
  65. # Adding local dns-cluster cron job
  66. cmd="sudo /usr/local/vesta/bin/v-update-sys-queue dns-cluster"
  67. check_cron=$(grep "$cmd" $VESTA/data/users/admin/cron.conf 2> /dev/null)
  68. if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then
  69. $BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
  70. fi
  71. # Logging
  72. log_event "$OK" "$ARGUMENTS"
  73. exit