v-delete-remote-dns-record 2.6 KB

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