v-add-remote-dns-record 3.2 KB

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