v-add-remote-dns-record 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. # info: add remote dns domain record
  3. # options: USER DOMAIN ID
  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. id=$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 '3' "$#" 'USER DOMAIN ID'
  21. is_format_valid 'user' 'domain' 'id'
  22. is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
  23. is_object_valid 'user' 'USER' "$user"
  24. is_object_valid 'dns' 'DOMAIN' "$domain"
  25. is_procces_running
  26. remote_dns_health_check
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Parsing record
  31. str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf)
  32. if [ -z "$str" ]; then
  33. pipe="$VESTA/data/queue/dns-cluster.pipe"
  34. queue_str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
  35. if [ ! -z "$queue_str" ]; then
  36. sed -i "$queue_str d" $pipe
  37. fi
  38. exit
  39. fi
  40. IFS=$'\n'
  41. for cluster in $(grep "SUSPENDED='no'" $VESTA/conf/dns-cluster.conf); do
  42. # Parsing remote host parameters
  43. eval $cluster
  44. # Syncing serial
  45. str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
  46. cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'domain' 'no'
  47. check_result $? "$HOST connection failed (soa sync)" $E_CONNECT
  48. # Syncing record
  49. str=$(grep "ID='$id'" $USER_DATA/dns/$domain.conf | sed 's/"/\\"/g')
  50. cluster_cmd v-insert-dns-record $DNS_USER $domain "$str" 'no'
  51. check_result $? "$HOST connection failed (record sync)" $E_CONNECT
  52. # Rebuilding dns zone
  53. cluster_cmd v-rebuild-dns-domain $DNS_USER $domain 'yes' 'no'
  54. check_result $? "$HOST connection failed (rebuild)" $E_CONNECT
  55. done
  56. #----------------------------------------------------------#
  57. # Vesta #
  58. #----------------------------------------------------------#
  59. # Updating pipe
  60. pipe="$VESTA/data/queue/dns-cluster.pipe"
  61. str=$(grep -n "$SCRIPT $1 $2 $3$" $pipe | cut -f1 -d: | head -n1)
  62. if [ ! -z "$str" ]; then
  63. sed -i "$str d" $pipe
  64. fi
  65. exit