v-add-remote-dns-host 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. validate_format '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. # Concatentating dns host string
  40. str="HOST='$host' PORT='$port' USER='$user' PASSWORD='$password'"
  41. str="$str DNS_USER='$dns_user' TYPE='$type' SUSPENDED='no'"
  42. str="$str TIME='$TIME' DATE='$DATE'"
  43. # Adding host to dns-cluster.conf
  44. echo "$str" >> $VESTA/conf/dns-cluster.conf
  45. chmod 660 $VESTA/conf/dns-cluster.conf
  46. # Enabling DNS_CLUSTER
  47. if [ -z "$(grep DNS_CLUSTER $VESTA/conf/vesta.conf)" ]; then
  48. sed -i "s/^STATS_/DNS_CLUSTER='yes'\nSTATS_/g" $VESTA/conf/vesta.conf
  49. else
  50. sed -i "s/DNS_CLUSTER=.*/DNS_CLUSTER='yes'/g" $VESTA/conf/vesta.conf
  51. fi
  52. # Enabling remote dns-cluster queue
  53. cluster_cmd v-add-cron-restart-job
  54. check_result $? "$HOST connection failed" $E_CONNECT
  55. # Syncing all domains
  56. $BIN/v-sync-dns-cluster $host
  57. check_result $? "$HOST sync failed" $E_CONNECT
  58. #----------------------------------------------------------#
  59. # Vesta #
  60. #----------------------------------------------------------#
  61. # Adding local dns-cluster cron job
  62. cmd="sudo /usr/local/vesta/bin/v-update-sys-queue dns-cluster"
  63. check_cron=$(grep "$cmd" $VESTA/data/users/admin/cron.conf 2> /dev/null)
  64. if [ -z "$check_cron" ] && [ ! -z "$CRON_SYSTEM" ]; then
  65. $BIN/v-add-cron-job admin '*/5' '*' '*' '*' '*' "$cmd"
  66. fi
  67. # Logging
  68. log_event "$OK" "$EVENT"
  69. exit