v-sync-dns-cluster 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
  19. check_result $E_NOTEXIST "dns-cluster.conf doesn't exist"
  20. fi
  21. if [ "$(ps auxf |grep -v grep |grep $BIN/$SCRIPT |wc -l)" -gt 2 ]; then
  22. check_result $E_EXISTS "another sync process already running"
  23. fi
  24. remote_dns_health_check 'no_email'
  25. #----------------------------------------------------------#
  26. # Action #
  27. #----------------------------------------------------------#
  28. # Selecting remote hosts
  29. IFS=$'\n'
  30. if [ -z $host ]; then
  31. hosts=$(cat $VESTA/conf/dns-cluster.conf |grep "SUSPENDED='no'")
  32. else
  33. hosts=$(grep "HOST='$host'" $VESTA/conf/dns-cluster.conf)
  34. fi
  35. # Starting cluster loop
  36. for cluster in $hosts; do
  37. # Parsing host values
  38. eval $cluster
  39. # Wiping remote domains
  40. cluster_cmd v-delete-dns-domains-src $DNS_USER $HOSTNAME no
  41. check_result $? "$HOST connection failed" $E_CONNECT
  42. # Syncing user domains
  43. user_list=$(ls $VESTA/data/users |grep -v "dns-cluster")
  44. for user in $user_list; do
  45. for str in $(cat $VESTA/data/users/$user/dns.conf); do
  46. # Syncing domain index
  47. eval $str
  48. cluster_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME ' ' no
  49. check_result $? "$HOST connection failed" $E_CONNECT
  50. # Syncing domain records
  51. tmp_file="/tmp/vst-sync.$DOMAIN"
  52. cluster_file $USER_DATA/$user/dns/$DOMAIN.conf $tmp_file
  53. check_result $? "$HOST connection failed" $E_CONNECT
  54. cluster_cmd v-insert-dns-records $DNS_USER $DOMAIN $tmp_file 'no'
  55. check_result $? "$HOST connection failed" $E_CONNECT
  56. done
  57. done
  58. # Rebuilding dns zones
  59. cluster_cmd v-rebuild-dns-domains $DNS_USER
  60. check_result $? "$TYPE connection to $HOST failed" $E_CONNECT
  61. done
  62. #----------------------------------------------------------#
  63. # Vesta #
  64. #----------------------------------------------------------#
  65. # Flushing dns-cluster queue
  66. rm -f $VESTA/data/queue/dns-cluster.pipe
  67. touch $VESTA/data/queue/dns-cluster.pipe
  68. chmod 660 $VESTA/data/queue/dns-cluster.pipe
  69. exit