forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathv_add_db_host
More file actions
executable file
·83 lines (63 loc) · 2.35 KB
/
Copy pathv_add_db_host
File metadata and controls
executable file
·83 lines (63 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# info: adding data base server
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument defenition
type="$1"
host="$2"
port="$3"
db_user="$4"
db_password="$5"
max_usr="${6-300}"
max_db="${7-300}"
template="${8-template1}"
# Importing variables
source $VESTA/conf/vars.conf
source $V_FUNC/shared_func.sh
source $V_FUNC/db_func.sh
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
# Checking arg number
args_usage='type host port db_user db_password [max_usr] [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 '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_USERS='$max_usr'";
new_str="$new_str 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='$tpl'";
new_str="$new_str MAX_USERS='$max_usr' MAX_DB='$max_db'";
new_str="$new_str 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
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Hidding db pass
V_EVENT=$(echo $V_EVENT | sed -e "s/$db_password/xxxxxx/g")
# Logging
log_event 'system' "$V_EVENT"
exit $OK