v-delete-database-host 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. # info: delete database server
  3. # options: TYPE HOST
  4. #
  5. # example: v-delete-database-host pgsql localhost
  6. #
  7. # This function for deleting the database host from hestia configuration. It will
  8. # be deleted if there are no databases created on it only.
  9. #----------------------------------------------------------#
  10. # Variables & Functions #
  11. #----------------------------------------------------------#
  12. # Argument definition
  13. type=$1
  14. host=$2
  15. # Includes
  16. # shellcheck source=/etc/hestiacp/hestia.conf
  17. source /etc/hestiacp/hestia.conf
  18. # shellcheck source=/usr/local/hestia/func/main.sh
  19. source $HESTIA/func/main.sh
  20. # shellcheck source=/usr/local/hestia/func/db.sh
  21. source $HESTIA/func/db.sh
  22. # load config file
  23. source_conf "$HESTIA/conf/hestia.conf"
  24. #----------------------------------------------------------#
  25. # Verifications #
  26. #----------------------------------------------------------#
  27. check_args '2' "$#" 'TYPE HOST'
  28. is_format_valid 'type' 'host'
  29. is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
  30. is_type_valid "$DB_SYSTEM" "$type"
  31. is_object_valid "../../conf/$type" 'HOST' "$host"
  32. is_dbhost_free
  33. # Perform verification if read-only mode is enabled
  34. check_hestia_demo_mode
  35. #----------------------------------------------------------#
  36. # Action #
  37. #----------------------------------------------------------#
  38. # Deleting server
  39. sed -i "/HOST='$host' /d" "$HESTIA/conf/$type.conf"
  40. # Delete RRD database
  41. rm -fr $HESTIA'/web/rrd/db/'$type'_'$host'.rrd'
  42. rm -fr $HESTIA'/web/rrd/db/'*-$type'_'$host'.*'
  43. #----------------------------------------------------------#
  44. # Hestia #
  45. #----------------------------------------------------------#
  46. # Logging
  47. $BIN/v-log-action "system" "Info" "Database" "Removed remote database host (Host: $host, Type: $type)."
  48. log_event "$OK" "$ARGUMENTS"
  49. exit