Просмотр исходного кода

Added documentation for DB function

Serghey Rodin 14 лет назад
Родитель
Сommit
81dbea9d63

+ 11 - 1
bin/v_add_db_base

@@ -1,5 +1,15 @@
 #!/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                     #

+ 16 - 10
bin/v_add_db_host

@@ -1,5 +1,13 @@
 #!/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                     #
@@ -11,9 +19,8 @@ host=$2
 port=$3
 db_user=$4
 db_password=$5
-max_usr=${6-300}
-max_db=${7-300}
-template=${8-template1}
+max_db=${6-300}
+template=${7-template1}
 
 
 # Importing variables
@@ -28,11 +35,11 @@ source $V_FUNC/db.func
 #----------------------------------------------------------#
 
 # 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"
 
 # 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'
 
 # Checking db system is enabled
@@ -50,6 +57,7 @@ case $type in
     pgsql) is_pgsql_host_alive ;;
 esac
 
+
 #----------------------------------------------------------#
 #                       Action                             #
 #----------------------------------------------------------#
@@ -57,13 +65,11 @@ 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_USERS='$max_usr'";
-            new_str="$new_str MAX_DB='$max_db' U_SYS_USERS=''";
+            new_str="$new_str PORT='$port' MAX_DB='$max_db' U_SYS_USERS=''";
             new_str="$new_str U_DB_BASES='0'  ACTIVE='yes' DATE='$V_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_USERS='$max_usr' MAX_DB='$max_db'";
-            new_str="$new_str 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'";;
 esac
 

+ 6 - 1
bin/v_change_db_password

@@ -1,5 +1,10 @@
 #!/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                     #

+ 6 - 1
bin/v_delete_db_base

@@ -1,5 +1,10 @@
 #!/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                     #

+ 5 - 1
bin/v_delete_db_dbases

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

+ 6 - 1
bin/v_delete_db_host

@@ -1,5 +1,10 @@
 #!/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                     #

+ 5 - 1
bin/v_list_db_base

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

+ 4 - 0
bin/v_list_db_bases

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

+ 6 - 2
bin/v_list_db_host

@@ -1,5 +1,9 @@
 #!/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                     #
@@ -101,7 +105,7 @@ is_db_host_valid
 conf=$V_DB/$type.conf
 
 # 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
 case $format in 

+ 7 - 4
bin/v_list_db_hosts

@@ -1,5 +1,9 @@
 #!/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                     #
@@ -9,7 +13,6 @@
 type=$1
 format=${2-shell}
 
-
 # Importing variables
 source $VESTA/conf/vars.conf
 source $V_FUNC/shared.func
@@ -37,13 +40,13 @@ is_type_valid 'db' "$type"
 conf=$V_DB/$type.conf
 
 # 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
 case $format in 
     json)   json_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 ;;
     *)      check_args '2' '0' 'type [format]'
 esac

+ 5 - 1
bin/v_suspend_db_base

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

+ 5 - 1
bin/v_suspend_db_bases

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

+ 5 - 1
bin/v_unsuspend_db_base

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

+ 5 - 1
bin/v_unsuspend_db_bases

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

+ 5 - 1
bin/v_update_db_base_disk

@@ -1,5 +1,9 @@
 #!/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                     #

+ 5 - 1
bin/v_update_db_bases_disk

@@ -1,5 +1,9 @@
 #!/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                     #

+ 10 - 13
func/db.func

@@ -57,7 +57,7 @@ get_next_db_host() {
             eval ${key%%=*}="${key#*=}"
         done
         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
         fi
 
@@ -76,7 +76,7 @@ get_next_db_host() {
             weight=$(echo "$U_DB_BASES * 100 / $MAX_DB"|bc)
             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"
                 ow="$weight"
             fi
@@ -95,8 +95,7 @@ get_next_db_host() {
 
             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_LIST="$HOST_LIST$HOST "
             fi
         done
@@ -122,8 +121,7 @@ get_next_db_host() {
             done
 
             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"
                 break
             fi
@@ -166,13 +164,12 @@ increase_db_value() {
     # Concatenating db string
     case $type in
         mysql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'";
-            new_str="$new_str PORT='$PORT' MAX_USERS='$MAX_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 PORT='$PORT' MAX_DB='$MAX_DB'";
+            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 DATE='$DATE'";;
         pgsql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'";
-            new_str="$new_str PORT='$PORT' TPL='$TPL'";
-            new_str="$new_str MAX_USERS='$MAX_USERS' MAX_DB='$MAX_DB'";
+            new_str="$new_str PORT='$PORT' TPL='$TPL' MAX_DB='$MAX_DB'";
             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 DATE='$DATE'";;
@@ -204,13 +201,13 @@ decrease_db_value() {
     # Concatenating db string
     case $type in
         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 U_DB_BASES='$U_DB_BASES'  ACTIVE='$ACTIVE'";
             new_str="$new_str DATE='$DATE'";;
         pgsql) new_str="HOST='$HOST' USER='$USER' PASSWORD='$PASSWORD'";
             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_DB_BASES='$U_DB_BASES' ACTIVE='$ACTIVE'";
             new_str="$new_str DATE='$DATE'";;