v-add-remote-dns-domain 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/bin/bash
  2. # info: add remote dns domain
  3. # options: USER DOMAIN [FLUSH]
  4. #
  5. # The function synchronize dns domain with the remote server.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. flush=$3
  13. # Includes
  14. source $VESTA/func/main.sh
  15. source $VESTA/func/remote.sh
  16. source $VESTA/conf/vesta.conf
  17. #----------------------------------------------------------#
  18. # Verifications #
  19. #----------------------------------------------------------#
  20. check_args '2' "$#" 'USER DOMAIN [FLUSH]'
  21. is_format_valid 'user' 'domain'
  22. is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
  23. is_procces_running
  24. remote_dns_health_check
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. # Parsing domain record
  29. str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf 2>/dev/null)
  30. if [ -z "$str" ]; then
  31. pipe="$VESTA/data/queue/dns-cluster.pipe"
  32. queue_str=$(grep -n "$SCRIPT $1 $2 " $pipe |cut -f1 -d: |head -n1)
  33. if [ ! -z "$queue_str" ]; then
  34. sed -i "$queue_str d" $pipe
  35. fi
  36. exit
  37. fi
  38. IFS=$'\n'
  39. for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
  40. # Parsing remote dns host parameters
  41. eval $cluster
  42. # Parsing domain parameters
  43. eval $str
  44. # Syncing domain data
  45. cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME $flush 'no'
  46. check_result $? "$HOST connection failed" $E_CONNECT
  47. # Syncing domain records
  48. tmp_file="/tmp/vst-sync.$DOMAIN"
  49. cluster_file $USER_DATA/dns/$DOMAIN.conf $tmp_file
  50. check_result $? "$HOST connection failed" $E_CONNECT
  51. # Inserting synced records
  52. cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
  53. check_result $? "$HOST connection failed" $E_CONNECT
  54. # Rebuilding dns zone
  55. cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
  56. check_result $? "$HOST connection failed" $E_CONNECT
  57. done
  58. #----------------------------------------------------------#
  59. # Vesta #
  60. #----------------------------------------------------------#
  61. # Updating pipe
  62. rm -f $tmpfile
  63. pipe="$VESTA/data/queue/dns-cluster.pipe"
  64. str=$(grep -n "$SCRIPT $1 $2 " $pipe | cut -f1 -d: | head -n1)
  65. if [ ! -z "$str" ]; then
  66. sed -i "$str d" $pipe
  67. fi
  68. exit