Added documentation for DB function

This commit is contained in:
Serghey Rodin 2011-12-26 16:22:43 +02:00
commit 81dbea9d63
17 changed files with 112 additions and 41 deletions

View file

@ -1,5 +1,15 @@
#!/bin/bash #!/bin/bash
# info: adding data base # info: add database
# arguments: user db db_user db_password type [host] [encoding]
#
# The function creates the database concatenating username and user_db.
# Supported yypes of databases you can get using v_list_sys_config script.
# If the host isn't stated and there are few hosts configured on the server,
# then the host will be defined by one of three algorithms. "First" will choose
# the first host in the list. "Random" will chose the host by a chance.
# "Weight" will distribute new database through hosts evenly. Algorithm and
# types of supported databases is designated in the main configuration file.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,13 @@
#!/bin/bash #!/bin/bash
# info: adding data base server # info: add new database server
# arguments: type host port db_user db_password [max_db] [tpl]
#
# 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
# you can set limit for number of databases on a host. Template parameter is
# used only for PostgreSQL and has an default value "template1". You can read
# more about templates in official PostgreSQL documentation.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #
@ -11,9 +19,8 @@ host=$2
port=$3 port=$3
db_user=$4 db_user=$4
db_password=$5 db_password=$5
max_usr=${6-300} max_db=${6-300}
max_db=${7-300} template=${7-template1}
template=${8-template1}
# Importing variables # Importing variables
@ -28,11 +35,11 @@ source $V_FUNC/db.func
#----------------------------------------------------------# #----------------------------------------------------------#
# Checking arg number # Checking arg number
args_usage='type host port db_user db_password [max_usr] [max_db] [tpl]' args_usage='type host port db_user db_password [max_db] [tpl]'
check_args '5' "$#" "$args_usage" check_args '5' "$#" "$args_usage"
# Checking argument format # Checking argument format
format_validation 'host' 'port' 'db_user' 'db_password' 'max_usr' 'max_db' format_validation 'host' 'port' 'db_user' 'db_password' 'max_db'
format_validation 'template' format_validation 'template'
# Checking db system is enabled # Checking db system is enabled
@ -50,6 +57,7 @@ case $type in
pgsql) is_pgsql_host_alive ;; pgsql) is_pgsql_host_alive ;;
esac esac
#----------------------------------------------------------# #----------------------------------------------------------#
# Action # # Action #
#----------------------------------------------------------# #----------------------------------------------------------#
@ -57,13 +65,11 @@ esac
# Concatentating db host string # Concatentating db host string
case $type in case $type in
mysql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'"; mysql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
new_str="$new_str PORT='$port' MAX_USERS='$max_usr'"; new_str="$new_str PORT='$port' MAX_DB='$max_db' U_SYS_USERS=''";
new_str="$new_str MAX_DB='$max_db' U_SYS_USERS=''";
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";; new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
pgsql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'"; pgsql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
new_str="$new_str PORT='$port' TPL='$template'"; new_str="$new_str PORT='$port' TPL='$template'";
new_str="$new_str MAX_USERS='$max_usr' MAX_DB='$max_db'"; new_str="$new_str MAX_DB='$max_db' U_SYS_USERS=''";
new_str="$new_str U_SYS_USERS=''";
new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";; new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
esac esac

View file

@ -1,5 +1,10 @@
#!/bin/bash #!/bin/bash
# info: changing userdb password # info: change database user password
# arguments: user db_name db_password
#
# The function for changing database user password to a database. It uses the
# full name of database as argument.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,10 @@
#!/bin/bash #!/bin/bash
# info: Deleting data base # info: delete database
# arguments: user database
#
# The function for deleting the database. If database user have access to
# another database, he will not be deleted.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: deleteing all user databases # info: delete user databases
# arguments: user
#
# The function deletes all user databases.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,10 @@
#!/bin/bash #!/bin/bash
# info: adding data base server # info: delete database serve
# arguments: type host
#
# The function for deleting the database host from vesta configuration. It will
# be deleted if there are no databases created on it only.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: listing data base # info: list database
# arguments: user database [format]
#
# The function for obtaining of all database's parameters.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: listing data bases # info: listing data bases
# arguments: user [format]
#
# The function for obtaining the list of all user's databases.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: listing data base servers # info: list database host
# arguments: type host [format]
#
# The function for obtaining host's database parameters.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #
@ -101,7 +105,7 @@ is_db_host_valid
conf=$V_DB/$type.conf conf=$V_DB/$type.conf
# Defining fileds to select # Defining fileds to select
fields='$HOST $PORT $MAX_USERS $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE' fields='$HOST $PORT $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE'
# Listing database # Listing database
case $format in case $format in

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: listing data base servers # info: list data base servers
# arguments: type [format]
#
# The function for obtaining the list of all hosts of the same databases' type.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #
@ -9,7 +13,6 @@
type=$1 type=$1
format=${2-shell} format=${2-shell}
# Importing variables # Importing variables
source $VESTA/conf/vars.conf source $VESTA/conf/vars.conf
source $V_FUNC/shared.func source $V_FUNC/shared.func
@ -37,13 +40,13 @@ is_type_valid 'db' "$type"
conf=$V_DB/$type.conf conf=$V_DB/$type.conf
# Defining fileds to select # Defining fileds to select
fields='$HOST $PORT $MAX_USERS $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE' fields='$HOST $PORT $MAX_DB $U_SYS_USERS $U_DB_BASES $ACTIVE $DATE'
# Listing database # Listing database
case $format in case $format in
json) json_list ;; json) json_list ;;
plain) nohead=1; shell_list;; plain) nohead=1; shell_list;;
shell) fields='$HOST $PORT $MAX_USERS $MAX_DB $U_DB_BASES $ACTIVE $DATE'; shell) fields='$HOST $PORT $MAX_DB $U_DB_BASES $ACTIVE $DATE';
shell_list | column -t ;; shell_list | column -t ;;
*) check_args '2' '0' 'type [format]' *) check_args '2' '0' 'type [format]'
esac esac

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: Suspending databse # info: suspend database
# arguments: user database
#
# The function for suspending a certain user database.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: Suspending databses # info: suspend databases
# arguments: user
#
# The function for suspending of all databases of a single user.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: Unsuspending databse # info: unsuspend database
# arguments: user database
#
# The function for unsuspending database.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: Unsuspending databses # info: unsuspend databases
# arguments: user
#
# The function for unsuspending all user's databases.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: updating disk usage for databae # info: update database disk usage
# arguments: user database
#
# The function recalculates disk usage for speciefic database.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
# info: updating disk usage for all databaes # info: update databases disk usage
# arguments: user
#
# The function recalculates disk usage for all user databases.
#----------------------------------------------------------# #----------------------------------------------------------#
# Variable&Function # # Variable&Function #

View file

@ -57,7 +57,7 @@ get_next_db_host() {
eval ${key%%=*}="${key#*=}" eval ${key%%=*}="${key#*=}"
done done
users=$(echo -e "${U_SYS_USERS//,/\n}"|wc -l) users=$(echo -e "${U_SYS_USERS//,/\n}"|wc -l)
if [ "$MAX_DB" -gt "$U_DB_BASES" ] && [ $MAX_USERS -gt "$users" ];then if [ "$MAX_DB" -gt "$U_DB_BASES" ]; then
host=$HOST host=$HOST
fi fi
@ -76,7 +76,7 @@ get_next_db_host() {
weight=$(echo "$U_DB_BASES * 100 / $MAX_DB"|bc) weight=$(echo "$U_DB_BASES * 100 / $MAX_DB"|bc)
users=$(echo -e "${U_SYS_USERS//,/\n}"|wc -l) users=$(echo -e "${U_SYS_USERS//,/\n}"|wc -l)
if [ "$ow" -gt "$weight" ] && [ $MAX_USERS -gt "$users" ]; then if [ "$ow" -gt "$weight" ]; then
host="$HOST" host="$HOST"
ow="$weight" ow="$weight"
fi fi
@ -95,8 +95,7 @@ get_next_db_host() {
users=$(echo -e "${U_SYS_USERS//,/\n}"|wc -l) users=$(echo -e "${U_SYS_USERS//,/\n}"|wc -l)
if [ "$MAX_DB" -gt "$U_DB_BASES" ] && [ $MAX_USERS -gt "$users" ] if [ "$MAX_DB" -gt "$U_DB_BASES" ]; then
then
HOST_LIST="$HOST_LIST$HOST " HOST_LIST="$HOST_LIST$HOST "
fi fi
done done
@ -122,8 +121,7 @@ get_next_db_host() {
done done
users=$(echo -e "${U_SYS_USERS//,/\n}"|wc -l) users=$(echo -e "${U_SYS_USERS//,/\n}"|wc -l)
if [ "$MAX_DB" -gt "$U_DB_BASES" ] && [ $MAX_USERS -gt "$users" ] if [ "$MAX_DB" -gt "$U_DB_BASES" ]; then
then
host="$HOST" host="$HOST"
break break
fi fi
@ -166,13 +164,12 @@ increase_db_value() {
# Concatenating db string # Concatenating db string
case $type in case $type in
mysql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'"; mysql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'";
new_str="$new_str PORT='$PORT' MAX_USERS='$MAX_USERS'"; new_str="$new_str PORT='$PORT' MAX_DB='$MAX_DB'";
new_str="$new_str MAX_DB='$MAX_DB' U_SYS_USERS='$U_SYS_USERS'"; new_str="$new_str U_SYS_USERS='$U_SYS_USERS'";
new_str="$new_str U_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'"; new_str="$new_str U_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'";
new_str="$new_str DATE='$DATE'";; new_str="$new_str DATE='$DATE'";;
pgsql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'"; pgsql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'";
new_str="$new_str PORT='$PORT' TPL='$TPL'"; new_str="$new_str PORT='$PORT' TPL='$TPL' MAX_DB='$MAX_DB'";
new_str="$new_str MAX_USERS='$MAX_USERS' MAX_DB='$MAX_DB'";
new_str="$new_str U_SYS_USERS='$U_SYS_USERS'"; new_str="$new_str U_SYS_USERS='$U_SYS_USERS'";
new_str="$new_str U_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'"; new_str="$new_str U_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'";
new_str="$new_str DATE='$DATE'";; new_str="$new_str DATE='$DATE'";;
@ -204,13 +201,13 @@ decrease_db_value() {
# Concatenating db string # Concatenating db string
case $type in case $type in
mysql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'"; mysql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'";
new_str="$new_str PORT='$PORT' MAX_USERS='$MAX_USERS'"; new_str="$new_str PORT='$PORT'";
new_str="$new_str MAX_DB='$MAX_DB' U_SYS_USERS='$U_SYS_USERS'"; new_str="$new_str MAX_DB='$MAX_DB' U_SYS_USERS='$U_SYS_USERS'";
new_str="$new_str U_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'"; new_str="$new_str U_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'";
new_str="$new_str DATE='$DATE'";; new_str="$new_str DATE='$DATE'";;
pgsql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'"; pgsql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'";
new_str="$new_str PORT='$PORT' TPL='$TPL'"; new_str="$new_str PORT='$PORT' TPL='$TPL'";
new_str="$new_str MAX_USERS='$MAX_USERS' MAX_DB='$MAX_DB'"; new_str="$new_str MAX_DB='$MAX_DB'";
new_str="$new_str U_SYS_USERS='$U_SYS_USERS'"; new_str="$new_str U_SYS_USERS='$U_SYS_USERS'";
new_str="$new_str U_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'"; new_str="$new_str U_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'";
new_str="$new_str DATE='$DATE'";; new_str="$new_str DATE='$DATE'";;