Files
VestaCP/bin/v_add_database_server

79 lines
2.5 KiB
Plaintext
Raw Normal View History

2011-06-14 00:22:25 +03:00
#!/bin/bash
2011-12-26 16:22:43 +02:00
# info: add new database server
2012-03-27 23:08:44 +03:00
# options: type host port dbuser dbpass [max_db] [charsets] [template]
2011-12-26 16:22:43 +02:00
#
# 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.
2011-06-14 00:22:25 +03:00
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
2011-11-01 12:27:45 +02:00
type=$1
host=$2
port=$3
2012-03-27 23:08:44 +03:00
dbuser=$4
dbpass=$5
2012-05-02 13:27:57 +03:00
A5='******'
2012-03-27 23:08:44 +03:00
charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
template=${8-template1}
2011-06-14 00:22:25 +03:00
2012-03-27 23:08:44 +03:00
# Includes
2012-03-06 22:07:06 +02:00
source $VESTA/conf/vesta.conf
2012-04-30 12:32:11 +03:00
source $VESTA/func/main.sh
2012-03-06 22:07:06 +02:00
source $VESTA/func/db.sh
2011-06-14 00:22:25 +03:00
2012-05-02 13:27:57 +03:00
# Hiding password
max_db=${6-500}
2011-06-14 00:22:25 +03:00
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
2012-03-27 23:08:44 +03:00
args_usage='type host port dbuser dbpass [max_db] [charsets] [tpl]'
2011-06-14 00:22:25 +03:00
check_args '5' "$#" "$args_usage"
2012-03-27 23:08:44 +03:00
validate_format 'host' 'port' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
is_system_enabled "$DB_SYSTEM"
2012-03-06 22:07:06 +02:00
is_type_valid "$DB_SYSTEM" "$type"
2012-03-27 23:08:44 +03:00
is_dbhost_new
2011-06-14 00:22:25 +03:00
case $type in
mysql) is_mysql_host_alive ;;
pgsql) is_pgsql_host_alive ;;
esac
2011-12-26 16:22:43 +02:00
2011-06-14 00:22:25 +03:00
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
# Concatentating db host string
case $type in
2012-03-27 23:08:44 +03:00
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'";;
2011-06-14 00:22:25 +03:00
esac
# Adding host to conf
2012-03-27 23:08:44 +03:00
echo "$str" >> $VESTA/conf/$type.conf
2012-03-06 22:07:06 +02:00
chmod 660 $VESTA/conf/$type.conf
2011-06-14 00:22:25 +03:00
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
2012-03-06 22:07:06 +02:00
log_event "$OK" "$EVENT"
2011-06-14 00:22:25 +03:00
2011-11-01 12:27:45 +02:00
exit