#!/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/tuliocp/tulio.conf
source /etc/tuliocp/tulio.conf
# shellcheck source=/usr/local/tulio/func/main.sh
source $TULIO/func/main.sh
# load config file
source_conf "$TULIO/conf/tulio.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_tulio_demo_mode

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

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

#----------------------------------------------------------#
#                       Tulio                             #
#----------------------------------------------------------#

# Logging
log_event "$OK" "$ARGUMENTS"

exit
