#!/bin/bash # info: add new database server # 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 # 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 dbuser=$4 dbpass=$5 A5='******' charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8} template=${8-template1} # Includes source $VESTA/conf/vesta.conf source $VESTA/func/main.sh source $VESTA/func/db.sh # Hiding password max_db=${6-500} #----------------------------------------------------------# # Verifications # #----------------------------------------------------------# args_usage='type host port dbuser dbpass [max_db] [charsets] [tpl]' check_args '5' "$#" "$args_usage" validate_format 'host' 'port' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template' is_system_enabled "$DB_SYSTEM" is_type_valid "$DB_SYSTEM" "$type" is_dbhost_new case $type in mysql) is_mysql_host_alive ;; pgsql) is_pgsql_host_alive ;; esac #----------------------------------------------------------# # Action # #----------------------------------------------------------# # Concatentating db host string case $type in 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 "$str" >> $VESTA/conf/$type.conf chmod 660 $VESTA/conf/$type.conf #----------------------------------------------------------# # Vesta # #----------------------------------------------------------# # Logging log_history "added $type database server $host" '' 'admin' log_event "$OK" "$EVENT" exit