#!/bin/bash
# info: unsuspend database server
# options: TYPE HOST
#
# example: v-unsuspend-database-host mysql localhost
#
# This function for unsuspending a database server.

#----------------------------------------------------------#
#                Variables & Functions                     #
#----------------------------------------------------------#

# Argument definition
type=$1
host=$2

# Includes
# shellcheck source=/etc/hestiacp/hestia.conf
source /etc/hestiacp/hestia.conf
# shellcheck source=/usr/local/hestia/func/main.sh
source $HESTIA/func/main.sh
# load config file
source_conf "$HESTIA/conf/hestia.conf"

#----------------------------------------------------------#
#                    Verifications                         #
#----------------------------------------------------------#

check_args '2' "$#" 'TYPE HOST'
is_format_valid 'type' 'host'
is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
is_object_valid "../../conf/$type" 'HOST' "$host"
is_object_suspended "../../conf/$type" 'HOST' "$host"

# Perform verification if read-only mode is enabled
check_hestia_demo_mode

#----------------------------------------------------------#
#                       Action                             #
#----------------------------------------------------------#

# Unsuspend database creation on a server
update_object_value "../../conf/$type" 'HOST' "$host" '$SUSPENDED' 'no'

#----------------------------------------------------------#
#                       Hestia                             #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit
