Refactoring stage III (db)

This commit is contained in:
Serghey Rodin 2012-03-27 23:08:44 +03:00
commit 33717629f7
21 changed files with 518 additions and 913 deletions

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add database
# options: user db db_user db_password type [host] [encoding]
# options: user database dbuser dbpass type [host] [charset]
#
# The function creates the database concatenating username and user_db.
# Supported yypes of databases you can get using v_list_sys_config script.
@ -22,8 +22,8 @@ dbuser="$user"_"$3"
dbpass=$4
type=$5
host=$6
encoding=${7-UTF8}
encoding=$(echo "$encoding" |tr '[:lower:]' '[:upper:]')
charset=${7-UTF8}
charset=$(echo "$charset" |tr '[:lower:]' '[:upper:]')
# Includes
source $VESTA/conf/vesta.conf
@ -35,8 +35,8 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
check_args '5' "$#" 'user db dbuser dbpass type [host] [encoding]'
validate_format 'user' 'database' 'dbuser' 'dbpass' 'encoding'
check_args '5' "$#" 'user database dbuser dbpass type [host] [charset]'
validate_format 'user' 'database' 'dbuser' 'dbpass' 'charset'
is_system_enabled "$DB_SYSTEM"
is_type_valid "$DB_SYSTEM" "$type"
is_object_valid 'user' 'USER' "$user"
@ -44,7 +44,8 @@ is_object_unsuspended 'user' 'USER' "$user"
is_object_free 'db' 'DB' "$database"
get_next_dbhost
is_object_valid "../../../conf/$type" 'HOST' "$host"
is_db_encoding_valid
is_object_unsuspended "../../../conf/$type" 'HOST' "$host"
is_charset_valid
is_package_full 'DATABASES'
#----------------------------------------------------------#
@ -53,8 +54,8 @@ is_package_full 'DATABASES'
# Switching on db type
case $type in
mysql) create_db_mysql ;;
pgsql) create_db_pgsql ;;
mysql) add_mysql_database ;;
pgsql) add_pgsql_database ;;
esac
@ -67,15 +68,15 @@ increase_dbhost_values
increase_user_value "$user" '$U_DATABASES'
# Adding db to db conf
v_str="DB='$database' USER='$dbuser' HOST='$host' TYPE='$type'"
v_str="$v_str CHARSET='$encoding' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
v_str="$v_str DATE='$DATE'"
echo "$v_str" >> $USER_DATA/db.conf
str="DB='$database' DBUSER='$dbuser' HOST='$host' TYPE='$type'"
str="$str CHARSET='$charset' U_DISK='0' SUSPENDED='no' TIME='$TIME'"
str="$str DATE='$DATE'"
echo "$str" >> $USER_DATA/db.conf
chmod 660 $USER_DATA/db.conf
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$user $database $dbuser ***** $type $host'"
EVENT="$EVENT ARGUMENTS='$user $database $dbuser ***** $type $host $charset'"
# Logging
log_history "$EVENT"

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: add new database server
# options: type host port db_user db_password [max_db] [tpl]
# options: type host port dbuser dbpass [max_db] [charsets] [template]
#
# The function add new database server to the server pool. It supports local
# and remote database servers, which is useful for clusters. By adding a host
@ -17,13 +17,13 @@
type=$1
host=$2
port=$3
db_user=$4
db_password=$5
dbuser=$4
dbpass=$5
max_db=${6-300}
template=${7-template1}
charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
template=${8-template1}
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
@ -33,24 +33,12 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
args_usage='type host port db_user db_password [max_db] [tpl]'
args_usage='type host port dbuser dbpass [max_db] [charsets] [tpl]'
check_args '5' "$#" "$args_usage"
# Checking argument format
validate_format 'host' 'port' 'db_user' 'db_password' 'max_db'
validate_format 'template'
# Checking db system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking db type
validate_format 'host' 'port' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
is_system_enabled "$DB_SYSTEM"
is_type_valid "$DB_SYSTEM" "$type"
# Checking host existance
is_db_host_new
# Checking host connection
is_dbhost_new
case $type in
mysql) is_mysql_host_alive ;;
pgsql) is_pgsql_host_alive ;;
@ -63,17 +51,17 @@ esac
# Concatentating db host string
case $type in
mysql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
new_str="$new_str PORT='$port' MAX_DB='$max_db' U_SYS_USERS=''";
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$DATE'";;
pgsql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
new_str="$new_str PORT='$port' TPL='$template'";
new_str="$new_str MAX_DB='$max_db' U_SYS_USERS=''";
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$DATE'";;
mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS='' ";
str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'";;
pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
str="$str TIME='$TIME' DATE='$DATE'";;
esac
# Adding host to conf
echo "$new_str" >> $VESTA/conf/$type.conf
echo "$str" >> $VESTA/conf/$type.conf
chmod 660 $VESTA/conf/$type.conf
@ -81,8 +69,10 @@ chmod 660 $VESTA/conf/$type.conf
# Vesta #
#----------------------------------------------------------#
# Hidding db pass
EVENT=$(echo $EVENT | sed -e "s/$db_password/xxxxxx/g")
# Hiding password
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$type $host $port $dbuser ****** $max_db $charsets"
EVENT="$EVENT $tpl'"
# Logging
log_event "$OK" "$EVENT"

View file

@ -1,6 +1,6 @@
#!/bin/bash
# info: change database user password
# options: user db_name db_password
# info: change database password
# options: user database dbpass
#
# The function for changing database user password to a database. It uses the
# full name of database as argument.
@ -13,9 +13,9 @@
# Argument defenition
user=$1
database=$2
db_password=$3
dbpass=$3
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
@ -25,41 +25,24 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '3' "$#" 'user db_name db_password'
# Checking argument format
validate_format 'user' 'database' 'db_password'
# Checking db system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
check_args '3' "$#" 'user database dbpass'
validate_format 'user' 'database' 'dbpass'
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
# Checking user is active
is_object_unsuspended 'user' 'USER' "$user"
# Checking db existance
is_db_valid
# Checking db is active
is_db_suspended
is_object_valid 'db' 'DB' "$database"
is_object_unsuspended 'db' 'DB' "$database"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Get database values
get_database_values
# Define database variables
db_user=$(get_db_value '$USER')
host=$(get_db_value '$HOST')
type=$(get_db_value '$TYPE')
# Switching on db type
case $type in
mysql) change_db_mysql_password ;;
pgsql) change_db_pgsql_password ;;
case $TYPE in
mysql) change_mysql_password ;;
pgsql) change_pgsql_password ;;
esac
@ -68,7 +51,8 @@ esac
#----------------------------------------------------------#
# Hiding password
EVENT="$DATE $SCRIPT $user $database *****"
EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
EVENT="$EVENT ARGUMENTS='$user $database *****'"
# Logging
log_event "$OK" "$EVENT"

View file

@ -14,7 +14,7 @@
user=$1
database=$2
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
@ -24,41 +24,26 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'user db_name'
# Checking argument format
check_args '2' "$#" 'user database'
validate_format 'user' 'database'
# Checking db system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
# Checking user is active
is_object_unsuspended 'user' 'USER' "$user"
# Checking db existance
is_db_valid
# Checking db is active
is_db_suspended
is_object_valid 'db' 'DB' "$database"
is_object_unsuspended 'db' 'DB' "$database"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Get some variables we do not have now
db_user=$(get_db_value '$USER')
host=$(get_db_value '$HOST')
type=$(get_db_value '$TYPE')
# Get database values
get_database_values
# Switching on db type
case $type in
mysql) del_db_mysql ;;
pgsql) del_db_pgsql ;;
case $TYPE in
mysql) delete_mysql_database ;;
pgsql) delete_pgsql_database ;;
esac
@ -66,15 +51,13 @@ esac
# Vesta #
#----------------------------------------------------------#
# Decreasing db value
decrease_db_value
# Deleting database
sed -i "/DB='$database' /d" $USER_DATA/db.conf
# Decreasing domain value
# Decreasing counters
decrease_dbhost_values
decrease_user_value "$user" '$U_DATABASES'
# Deleting vesta db record
del_db_vesta
# Logging
log_event "$OK" "$EVENT"

View file

@ -1,5 +1,5 @@
#!/bin/bash
# info: delete database serve
# info: delete database server
# options: type host
#
# The function for deleting the database host from vesta configuration. It will
@ -24,31 +24,19 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'type host'
# Checking argument format
validate_format 'host'
# Checking db system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking db type
check_args '2' "$#" "type host"
validate_format 'type' 'host'
is_system_enabled "$DB_SYSTEM"
is_type_valid "$DB_SYSTEM" "$type"
# Checking host existance
is_db_host_valid
# Checking db host users
is_db_host_free
is_object_valid "../../conf/$type" 'HOST' "$host"
is_dbhost_free
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Deleting host from conf
del_dbhost_vesta
# Deleting server
sed -i "/HOST='$host' /d" $VESTA/conf/$type.conf
#----------------------------------------------------------#

View file

@ -12,53 +12,29 @@
# Argument defenition
user=$1
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'user'
# Checking argument format
validate_format 'user'
# Checking web system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining config
conf="$USER_DATA/db.conf"
# Defining fileds to select
field='$DB'
# Defining search string
search_string="SUSPENDED='no'"
# Parsing unsuspeneded domains
databases=$(db_clear_search)
# Starting delete loop
for database in $databases; do
$BIN/v_delete_db_base "$user" "$database"
rv="$?"
if [ "$rv" -ne '0' ]; then
log_event 'debug' "$rv $EVENT"
exit $rv
fi
for database in $(search_objects 'db' 'SUSPENDED' "no" 'DB'); do
$BIN/v_delete_database "$user" "$database"
done

View file

@ -14,33 +14,18 @@ user=$1
database=$2
format=${3-shell}
# Importing variables
# Includes
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
# Json function
json_list_db() {
i=1
# Define words number
last_word=$(echo "$fields" | wc -w)
# Reading file line by line
line=$(grep "DB='$database'" $conf)
# Print top bracket
echo '{'
# Parsing key=value
eval $line
# Starting output loop
for field in $fields; do
# Parsing key=value
eval value=$field
# Checking first field
if [ "$i" -eq 1 ]; then
echo -e "\t\"$value\": {"
else
@ -50,30 +35,18 @@ json_list_db() {
echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
fi
fi
# Updating iterator
(( ++i))
done
# If there was any output
if [ -n "$value" ]; then
echo -e "\t}"
fi
# Printing bottom json bracket
echo -e '}'
}
# Shell list for single database
shell_list_db() {
# Reading file line by line
line=$(grep "DB='$database'" $conf)
# Parsing key=value
eval $line
# Print result line
for field in $fields; do
eval key="$field"
echo "${field//$/}: $key "
@ -85,28 +58,20 @@ shell_list_db() {
# Verifications #
#----------------------------------------------------------#
# Checking args
check_args '2' "$#" 'user db_name [format]'
# Checking argument format
check_args '2' "$#" 'user database [format]'
validate_format 'user' 'database'
# Checking user
is_object_valid 'user' 'USER' "$user"
# Checking database exist
is_db_valid
is_object_valid 'db' 'DB' "$database"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining config
conf=$USER_DATA/db.conf
# Defining fileds to select
fields='$DB $USER $HOST $TYPE $CHARSET $U_DISK $SUSPENDED $DATE'
conf=$USER_DATA/db.conf
fields='$DB $DBUSER $HOST $TYPE $CHARSET $U_DISK $SUSPENDED $TIME $DATE'
# Listing database
case $format in

View file

@ -1,8 +1,8 @@
#!/bin/bash
# info: list database host
# info: list database server
# options: type host [format]
#
# The function for obtaining host's database parameters.
# The function for obtaining database server parameters.
#----------------------------------------------------------#
@ -14,34 +14,18 @@ type=$1
host=$2
format=${3-shell}
# Importing variables
# Includes
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
# Json function
json_list_dbhost() {
# Definigng variables
i=1
# Define words number
fields_count=$(echo "$fields" | wc -w)
# Reading file line by line
line=$(grep "HOST='$host'" $conf)
# Print top bracket
echo '{'
# Assign key=value
eval $line
# Starting output loop
for field in $fields; do
# Parsing key=value
eval value=$field
# Checking first field
if [ "$i" -eq 1 ]; then
echo -e "\t\"$value\": {"
else
@ -53,25 +37,16 @@ json_list_dbhost() {
fi
(( ++i))
done
# If there was any output
if [ -n "$value" ]; then
echo -e "\t}"
fi
# Printing bottom json bracket
echo -e "}"
}
# Shell function
shell_list_dbhost() {
# Reading file line by line
line=$(grep "HOST='$host'" $conf)
# Parsing key=value
eval $line
# Print result line
for field in $fields; do
eval key="$field"
echo "${field//$/}: $key"
@ -83,28 +58,19 @@ shell_list_dbhost() {
# Verifications #
#----------------------------------------------------------#
# Checking args
check_args '2' "$#" 'type host [format]'
# Checking argument format
validate_format 'host'
# Checking db type
is_type_valid "$DB_SYSTEM" "$type"
# Checking db host
is_db_host_valid
is_object_valid "../../conf/$type" 'HOST' "$host"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining config type
conf=$VESTA/conf/$type.conf
# Defining fileds to select
fields='$HOST $PORT $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE'
conf=$VESTA/conf/$type.conf
fields='$HOST $PORT $CHARSETS $MAX_DB $U_SYS_USERS $U_DB_BASES $TPL $SUSPENDED'
fields="$fields \$TIME \$DATE"
# Listing database
case $format in

View file

@ -1,5 +1,5 @@
#!/bin/bash
# info: list data base servers
# info: list database servers
# options: type [format]
#
# The function for obtaining the list of all hosts of the same databases' type.
@ -13,7 +13,7 @@
type=$1
format=${2-shell}
# Importing variables
# Includes
source $VESTA/func/shared.sh
@ -24,25 +24,21 @@ source $VESTA/func/shared.sh
# Checking args
check_args '1' "$#" 'type [format]'
# Checking db type
is_type_valid "$DB_SYSTEM" "$type"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining config type
conf=$VESTA/conf/$type.conf
# Defining fileds to select
fields='$HOST $PORT $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE'
conf=$VESTA/conf/$type.conf
fields='$HOST $PORT $CHARSETS $MAX_DB $U_SYS_USERS $U_DB_BASES $TPL $SUSPENDED'
fields="$fields \$TIME \$DATE"
# Listing database
case $format in
json) json_list ;;
plain) nohead=1; shell_list;;
shell) fields='$HOST $PORT $MAX_DB $U_DB_BASES $ACTIVE $DATE';
shell) fields='$HOST $PORT $MAX_DB $U_DB_BASES $SUSPENDED $DATE';
shell_list | column -t ;;
*) check_args '2' '0' 'type [format]'
esac

View file

@ -1,5 +1,5 @@
#!/bin/bash
# info: listing data bases
# info: listing databases
# options: user [format]
#
# The function for obtaining the list of all user's databases.
@ -13,7 +13,7 @@
user=$1
format=${2-shell}
# Importing variables
# Includes
source $VESTA/func/shared.sh
@ -21,13 +21,8 @@ source $VESTA/func/shared.sh
# Verifications #
#----------------------------------------------------------#
# Checking args
check_args '1' "$#" 'user [format]'
# Checking argument format
validate_format 'user'
# Checking user
is_object_valid 'user' 'USER' "$user"
@ -35,17 +30,15 @@ is_object_valid 'user' 'USER' "$user"
# Action #
#----------------------------------------------------------#
# Defining config
conf=$USER_DATA/db.conf
# Defining fileds to select
fields='$DB $USER $HOST $TYPE $CHARSET $U_DISK $SUSPENDED $DATE'
conf=$USER_DATA/db.conf
fields='$DB $DBUSER $HOST $TYPE $CHARSET $U_DISK $SUSPENDED $TIME $DATE'
# Listing databases
case $format in
json) json_list ;;
plain) nohead=1; shell_list ;;
shell) fields='$DB $USER $HOST $TYPE $U_DISK $DATE';
shell) fields='$DB $DBUSER $HOST $TYPE $U_DISK $DATE';
shell_list | column -t ;;
*) check_args '1' '0' 'user [format]'
esac

View file

@ -13,7 +13,7 @@
user=$1
database=$2
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
@ -23,38 +23,26 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'user db_name'
# Checking argument format
check_args '2' "$#" 'user database'
validate_format 'user' 'database'
# Checking db system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
# Checking db existance
is_db_valid
# Checking db is active
is_db_suspended
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'db' 'DB' "$database"
is_object_unsuspended 'db' 'DB' "$database"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Define database variables
db_user=$(get_db_value '$USER')
host=$(get_db_value '$HOST')
type=$(get_db_value '$TYPE')
# Get database values
get_database_values
# Switching on db type
case $type in
mysql) suspend_db_mysql ;;
pgsql) suspend_db_pgsql ;;
mysql) suspend_mysql_database ;;
pgsql) suspend_pgsql_database ;;
esac
@ -63,7 +51,7 @@ esac
#----------------------------------------------------------#
# Updating db value
update_db_base_value '$SUSPENDED' 'yes'
update_object_value 'db' 'DB' "$database" '$SUSPENDED' 'yes'
increase_user_value "$user" '$SUSPENDED_DB'
# Logging

47
bin/v_suspend_database_server Executable file
View file

@ -0,0 +1,47 @@
#!/bin/bash
# info: suspend database server
# options: type host
#
# The function for suspending a database server.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
type=$1
host=$2
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'type host'
validate_format 'type' 'host'
is_system_enabled "$DB_SYSTEM"
is_object_valid "../../conf/$type" 'HOST' "$host"
is_object_unsuspended "../../conf/$type" 'HOST' "$host"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Suspend database creation on a server
update_object_value "../../conf/$type" 'HOST' "$host" '$SUSPENDED' 'yes'
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -12,26 +12,18 @@
# Argument defenition
user=$1
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'user'
# Checking argument format
validate_format 'user'
# Checking db system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
@ -39,21 +31,9 @@ is_object_valid 'user' 'USER' "$user"
# Action #
#----------------------------------------------------------#
# Defining config
conf="$USER_DATA/db.conf"
# Defining fileds to select
field='$DB'
# Defining search string
search_string="SUSPENDED='no'"
# Parsing unsuspeneded domains
databases=$(db_clear_search)
# Starting suspend loop
for database in $databases; do
$BIN/v_suspend_db_base "$user" "$database"
for database in $(search_objects 'db' 'SUSPENDED' "no" 'DB'); do
$BIN/v_suspend_database "$user" "$database"
done

View file

@ -13,7 +13,7 @@
user=$1
database=$2
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
@ -23,38 +23,25 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'user db_name'
# Checking argument format
check_args '2' "$#" 'user database'
validate_format 'user' 'database'
# Checking db system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
# Checking db existance
is_db_valid
# Checking db is active
is_db_unsuspended
is_object_valid 'db' 'DB' "$database"
is_object_suspended 'db' 'DB' "$database"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Define database variables
db_user=$(get_db_value '$USER')
host=$(get_db_value '$HOST')
type=$(get_db_value '$TYPE')
# Get database values
get_database_values
# Switching on db type
case $type in
mysql) unsuspend_db_mysql ;;
pgsql) unsuspend_db_pgsql ;;
mysql) unsuspend_mysql_database ;;
pgsql) unsuspend_pgsql_database ;;
esac
@ -63,7 +50,7 @@ esac
#----------------------------------------------------------#
# Updating db value
update_db_base_value '$SUSPENDED' 'no'
update_object_value 'db' 'DB' "$database" '$SUSPENDED' 'no'
decrease_user_value "$user" '$SUSPENDED_DB'
# Logging

47
bin/v_unsuspend_database_server Executable file
View file

@ -0,0 +1,47 @@
#!/bin/bash
# info: unsuspend database server
# options: type host
#
# The function for unsuspending a database server.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
type=$1
host=$2
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '2' "$#" 'type host'
validate_format 'type' 'host'
is_system_enabled "$DB_SYSTEM"
is_object_valid "../../conf/$type" 'HOST' "$host"
is_object_suspended "../../conf/$type" 'HOST' "$host"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Unsuspend database creation on a server
update_object_value "../../conf/$type" 'HOST' "$host" '$SUSPENDED' 'no'
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -22,16 +22,9 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'user'
# Checking argument format
validate_format 'user'
# Checking db system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
@ -39,21 +32,9 @@ is_object_valid 'user' 'USER' "$user"
# Action #
#----------------------------------------------------------#
# Defining config
conf="$USER_DATA/db.conf"
# Defining fileds to select
field='$DB'
# Defining search string
search_string="SUSPENDED='yes'"
# Parsing unsuspeneded domains
databases=$(db_clear_search)
# Starting suspend loop
for database in $databases; do
$BIN/v_unsuspend_db_base "$user" "$database"
# Starting unsuspend loop
for database in $(search_objects 'db' 'SUSPENDED' "yes" 'DB'); do
$BIN/v_unsuspend_database "$user" "$database"
done

View file

@ -13,7 +13,7 @@
user=$1
database=$2
# Importing variables
# Includes
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
@ -23,54 +23,35 @@ source $VESTA/func/db.sh
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '2' "$#" 'user db_name'
# Checking argument format
check_args '2' "$#" 'user database'
validate_format 'user' 'database'
# Checking web system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
# Checking db existance
is_db_valid
# Checking db is active
is_db_suspended
is_object_unsuspended 'user' 'USER' "$user"
is_object_valid 'db' 'DB' "$database"
is_object_unsuspended 'db' 'DB' "$database"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Get some variables we do not have now
db_user=$(get_db_value '$USER')
host=$(get_db_value '$HOST')
type=$(get_db_value '$TYPE')
# Get database values
get_database_values
# Switching on db type
case $type in
mysql) disk_usage=$(get_disk_db_mysql); ret_val="$?" ;;
pgsql) disk_usage=$(get_disk_db_pgsql); ret_val="$?" ;;
case $TYPE in
mysql) get_mysql_disk_usage ;;
pgsql) get_pgsql_disk_usage ;;
esac
# Checking ret_val
if [ "$ret_val" -ne '0' ]; then
exit $ret_val
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Updating disk value in config
update_db_base_value '$U_DISK' "$disk_usage"
# Recalculating user disk space
# Updating disk usage
update_object_value 'db' 'DB' "$database" '$U_DISK' "$usage"
recalc_user_disk_usage
# Logging

47
bin/v_update_databases_disk Executable file
View file

@ -0,0 +1,47 @@
#!/bin/bash
# info: update databases disk usage
# options: user
#
# The function recalculates disk usage for all user databases.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
# Importing variables
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
check_args '1' "$#" 'user'
validate_format 'user'
is_system_enabled "$DB_SYSTEM"
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Starting update loop
for database in $(search_objects 'db' 'SUSPENDED' "no" 'DB'); do
$BIN/v_update_database_disk "$user" "$database"
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_event "$OK" "$EVENT"
exit

View file

@ -1,83 +0,0 @@
#!/bin/bash
# info: update databases disk usage
# options: user
#
# The function recalculates disk usage for all user databases.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
user=$1
# Importing variables
source $VESTA/conf/vesta.conf
source $VESTA/func/shared.sh
source $VESTA/func/db.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
check_args '1' "$#" 'user'
# Checking argument format
validate_format 'user'
# Checking web system is enabled
is_system_enabled 'DB_SYSTEM'
# Checking user
is_object_valid 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Defining config
conf="$USER_DATA/db.conf"
# Defining fileds to select
field='$DB'
# Defining search string
search_string="SUSPENDED='no'"
# Parsing unsuspeneded domains
databases=$(db_clear_search)
for database in $databases; do
# Define database variables
db_user=$(get_db_value '$USER')
host=$(get_db_value '$HOST')
type=$(get_db_value '$TYPE')
# Switching on db type
case $type in
mysql) disk_usage=$(get_disk_db_mysql); ret_val="$?" ;;
pgsql) disk_usage=$(get_disk_db_pgsql); ret_val="$?" ;;
esac
# Updating disk value in config
if [ "$ret_val" -eq '0' ]; then
update_db_base_value '$U_DISK' "$disk_usage"
fi
done
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Recalculating user disk space
recalc_user_disk_usage
# Logging
log_event "$OK" "$EVENT"
exit