| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- #!/bin/bash
- # info: add new database server
- # options: 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 #
- #----------------------------------------------------------#
- # Argument defenition
- type=$1
- host=$2
- port=$3
- db_user=$4
- db_password=$5
- max_db=${6-300}
- template=${7-template1}
- # Importing variables
- source $VESTA/conf/vars.conf
- source $V_CONF/vesta.conf
- source $V_FUNC/shared.func
- source $V_FUNC/db.func
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- # Checking arg number
- 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_db'
- format_validation 'template'
- # Checking db system is enabled
- is_system_enabled 'db'
- # Checking db type
- is_type_valid 'db' "$type"
- # Checking host existance
- is_db_host_new
- # Checking host connection
- case $type in
- mysql) is_mysql_host_alive ;;
- pgsql) is_pgsql_host_alive ;;
- esac
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # 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='$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_DB='$max_db' U_SYS_USERS=''";
- new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
- esac
- # Adding host to conf
- echo "$new_str" >> $V_DB/$type.conf
- chmod 640 $V_DB/$type.conf
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- # Hidding db pass
- V_EVENT=$(echo $V_EVENT | sed -e "s/$db_password/xxxxxx/g")
- # Logging
- log_event 'system' "$V_EVENT"
- exit
|