v-delete-remote-dns-domain 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/bin/bash
  2. # info: delete remote dns domain
  3. # options: USER DOMAIN
  4. #
  5. # The function synchronize dns 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. if [ ! -e "$VESTA/conf/dns-cluster.conf" ]; then
  23. echo "Error: dns-cluster.conf doesn't exist"
  24. log_event "$E_NOTEXIST $EVENT"
  25. exit $E_NOTEXIST
  26. fi
  27. number_of_proc=$(ps auxf | grep -v grep | grep $VESTA/bin/$SCRIPT | wc -l)
  28. if [ "$number_of_proc" -gt 2 ]; then
  29. echo "Error: another sync process already exists"
  30. log_event "$E_EXISTS $EVENT"
  31. exit $E_EXISTS
  32. fi
  33. #----------------------------------------------------------#
  34. # Action #
  35. #----------------------------------------------------------#
  36. old_ifs="$IFS"
  37. IFS=$'\n'
  38. # Starting cluster loop
  39. for cluster_str in $(cat $VESTA/conf/dns-cluster.conf); do
  40. # Get host values
  41. eval $cluster_str
  42. # Check connection type
  43. if [ -z "TYPE" ]; then
  44. TYPE='api'
  45. fi
  46. # Switch on connection type
  47. case $TYPE in
  48. ssh) send_cmd="send_ssh_cmd" ;;
  49. *) send_cmd="send_api_cmd" ;;
  50. esac
  51. # Check host connection
  52. $send_cmd v-list-sys-config
  53. if [ $? -ne 0 ]; then
  54. echo "Error: $TYPE connection to $HOST failed"
  55. log_event "$E_CONNECT $EVENT"
  56. exit $E_CONNECT
  57. fi
  58. # Check recipient dns user
  59. if [ -z "$DNS_USER" ]; then
  60. DNS_USER='dns-cluster'
  61. fi
  62. $send_cmd v-list-user $DNS_USER
  63. if [ $? -ne 0 ]; then
  64. echo "Error: dns user $DNS_USER doesn't exist"
  65. log_event "$E_NOTEXIST $EVENT"
  66. exit $E_NOTEXIST
  67. fi
  68. # Check dns exceptions
  69. if [ -z "$DNS_CLUSTER_IGNORE" ]; then
  70. DNS_CLUSTER_IGNORE='dns-cluster'
  71. fi
  72. # Sync domain
  73. $send_cmd v-delete-dns-domain $DNS_USER $domain 'no'
  74. done
  75. # Update pipe
  76. pipe="$VESTA/data/queue/dns-cluster.pipe"
  77. str=$(grep -n "$SCRIPT $1 $2$" $pipe | cut -f1 -d: | head -n1)
  78. if [ ! -z "$str" ]; then
  79. sed -i "$str d" $pipe
  80. fi
  81. #----------------------------------------------------------#
  82. # Vesta #
  83. #----------------------------------------------------------#
  84. exit