v-sync-dns-cluster 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #!/bin/bash
  2. # info: synchronize dns domains
  3. # options: HOST
  4. # The function synchronize all dns domains.
  5. #----------------------------------------------------------#
  6. # Variable&Function #
  7. #----------------------------------------------------------#
  8. # Argument definition
  9. host=$1
  10. # Includes
  11. source $VESTA/func/main.sh
  12. source $VESTA/func/remote.sh
  13. source $VESTA/conf/vesta.conf
  14. #----------------------------------------------------------#
  15. # Verifications #
  16. #----------------------------------------------------------#
  17. is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
  18. is_procces_running
  19. remote_dns_health_check 'no_email'
  20. #----------------------------------------------------------#
  21. # Action #
  22. #----------------------------------------------------------#
  23. # Selecting remote hosts
  24. IFS=$'\n'
  25. if [ -z $host ]; then
  26. hosts=$(cat $VESTA/conf/dns-cluster.conf |grep "SUSPENDED='no'")
  27. else
  28. hosts=$(grep "HOST='$host'" $VESTA/conf/dns-cluster.conf)
  29. fi
  30. # Starting cluster loop
  31. for cluster in $hosts; do
  32. # Parsing host values
  33. eval $cluster
  34. # Wiping remote domains
  35. cluster_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME no
  36. check_result $? "$HOST connection failed" $E_CONNECT
  37. # Syncing user domains
  38. user_list=$(ls $VESTA/data/users |grep -v "dns-cluster")
  39. for user in $user_list; do
  40. for str in $(cat $VESTA/data/users/$user/dns.conf); do
  41. # Syncing domain index
  42. eval $str
  43. cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME ' ' no
  44. check_result $? "$HOST connection failed" $E_CONNECT
  45. # Syncing domain records
  46. tmp_file="/tmp/vst-sync.$DOMAIN"
  47. cluster_file $USER_DATA/$user/dns/$DOMAIN.conf $tmp_file
  48. check_result $? "$HOST connection failed" $E_CONNECT
  49. cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
  50. check_result $? "$HOST connection failed" $E_CONNECT
  51. done
  52. done
  53. # Rebuilding dns zones
  54. cluster_cmd v-rebuild-dns-domains $DNS_USER
  55. check_result $? "$TYPE connection to $HOST failed" $E_CONNECT
  56. done
  57. #----------------------------------------------------------#
  58. # Vesta #
  59. #----------------------------------------------------------#
  60. # Flushing dns-cluster queue
  61. rm -f $VESTA/data/queue/dns-cluster.pipe
  62. touch $VESTA/data/queue/dns-cluster.pipe
  63. chmod 660 $VESTA/data/queue/dns-cluster.pipe
  64. exit