v-change-remote-dns-domain-ttl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/bin/bash
  2. # info: change remote dns domain TTL
  3. # options: USER DOMAIN
  4. #
  5. # The function synchronize dns domain with the remote server.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. domain=$2
  12. # Includes
  13. source $VESTA/conf/vesta.conf
  14. source $VESTA/func/main.sh
  15. source $VESTA/func/remote.sh
  16. #----------------------------------------------------------#
  17. # Verifications #
  18. #----------------------------------------------------------#
  19. check_args '2' "$#" 'USER DOMAIN'
  20. validate_format 'user' 'domain'
  21. is_system_enabled "$DNS_CLUSTER"
  22. is_object_valid 'user' 'USER' "$user"
  23. is_object_valid 'dns' 'DOMAIN' "$domain"
  24. if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
  25. echo "Error: dns-cluster.conf doesn't exist"
  26. log_event "$E_NOTEXIST $EVENT"
  27. exit $E_NOTEXIST
  28. fi
  29. number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
  30. if [ "$number_of_proc" -gt 2 ]; then
  31. echo "Error: another sync process already exists"
  32. log_event "$E_EXISTS $EVENT"
  33. exit $E_EXISTS
  34. fi
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. old_ifs="$IFS"
  39. IFS=$'\n'
  40. # Starting cluster loop
  41. for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
  42. # Get host values
  43. eval $cluster_str
  44. # Check connection type
  45. if [ -z "TYPE" ]; then
  46. TYPE='api'
  47. fi
  48. # Switch on connection type
  49. case $TYPE in
  50. ssh) send_cmd="send_ssh_cmd" ;;
  51. *) send_cmd="send_api_cmd" ;;
  52. esac
  53. # Check host connection
  54. $send_cmd v-list-sys-config
  55. if [ $? -ne 0 ]; then
  56. echo "Error: $TYPE connection to $HOST failed"
  57. log_event "$E_CONNECT $EVENT"
  58. exit $E_CONNECT
  59. fi
  60. # Check recipient dns user
  61. if [ -z "$DNS_USER" ]; then
  62. DNS_USER='dns-cluster'
  63. fi
  64. $send_cmd v-list-user $DNS_USER
  65. if [ $? -ne 0 ]; then
  66. echo "Error: dns user $DNS_USER doesn't exist"
  67. log_event "$E_NOTEXIST $EVENT"
  68. exit $E_NOTEXIST
  69. fi
  70. # Check dns exceptions
  71. if [ -z "$DNS_CLUSTER_IGNORE" ]; then
  72. DNS_CLUSTER_IGNORE='dns-cluster'
  73. fi
  74. # Sync domain
  75. str=$(grep "DOMAIN='$domain'" $USER_DATA/dns.conf)
  76. eval $str
  77. $send_cmd v-insert-dns-domain $DNS_USER "$str" $HOSTNAME 'no'
  78. # Rebuild dns zone
  79. $send_cmd v-rebuild-dns-domain $DNS_USER $domain no
  80. if [ $? -ne 0 ]; then
  81. echo "Error: $TYPE connection to $HOST failed (rebuild)"
  82. log_event "$E_CONNECT $EVENT"
  83. exit $E_CONNECT
  84. fi
  85. done
  86. # Update pipe
  87. pipe="$VESTA/data/queue/dns-cluster.pipe"
  88. str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
  89. if [ ! -z "$str" ]; then
  90. sed -i "$str d" $pipe
  91. fi
  92. #----------------------------------------------------------#
  93. # Vesta #
  94. #----------------------------------------------------------#
  95. exit