v-delete-remote-dns-host 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # info: delete remote dns host
  3. # options: HOST
  4. #
  5. # The function for deleting the remote dns host from vesta configuration.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. host=$1
  11. # Includes
  12. source $VESTA/func/main.sh
  13. source $VESTA/func/remote.sh
  14. source $VESTA/conf/vesta.conf
  15. #----------------------------------------------------------#
  16. # Verifications #
  17. #----------------------------------------------------------#
  18. check_args '1' "$#" 'HOST'
  19. validate_format 'host'
  20. is_system_enabled "$DNS_CLUSTER" 'DNS_CLUSTER'
  21. is_object_valid "../../conf/dns-cluster" 'HOST' "$host"
  22. #----------------------------------------------------------#
  23. # Action #
  24. #----------------------------------------------------------#
  25. eval $(grep $host $VESTA/conf/dns-cluster.conf)
  26. case $TYPE in
  27. ssh) send_cmd="send_ssh_cmd" ;;
  28. *) send_cmd="send_api_cmd" ;;
  29. esac
  30. # Check host connection
  31. $send_cmd v-list-sys-config
  32. if [ $? -eq 0 ]; then
  33. # Deleting domains
  34. $BIN/v-delete-remote-dns-domains $host >>/dev/null 2>&1
  35. $send_cmd v-add-cron-restart-job
  36. fi
  37. # Deleting server
  38. sed -i "/HOST='$host' /d" $VESTA/conf/dns-cluster.conf
  39. # Delete DNS_CLUSTER key
  40. check_cluster=$(grep HOST $VESTA/conf/dns-cluster.conf |wc -l)
  41. if [ "$check_cluster" -eq '0' ]; then
  42. rm -f $VESTA/conf/dns-cluster.conf
  43. sed -i "/DNS_CLUSTER=/d" $VESTA/conf/vesta.conf
  44. # Delete cron job
  45. cmd="sudo /usr/local/vesta/bin/v-update-sys-queue dns-cluster"
  46. check_cron=$(grep "$cmd" $VESTA/data/users/admin/cron.conf 2> /dev/null)
  47. if [ ! -z "$check_cron" ]; then
  48. eval $check_cron
  49. $BIN/v-delete-cron-job admin "$JOB"
  50. fi
  51. fi
  52. #----------------------------------------------------------#
  53. # Vesta #
  54. #----------------------------------------------------------#
  55. # Logging
  56. log_history "deleted remote dns server $host" '' 'admin'
  57. log_event "$OK" "$EVENT"
  58. exit