v_add_database_server 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # info: add new database server
  3. # options: type host port dbuser dbpass [max_db] [charsets] [template]
  4. #
  5. # The function add new database server to the server pool. It supports local
  6. # and remote database servers, which is useful for clusters. By adding a host
  7. # you can set limit for number of databases on a host. Template parameter is
  8. # used only for PostgreSQL and has an default value "template1". You can read
  9. # more about templates in official PostgreSQL documentation.
  10. #----------------------------------------------------------#
  11. # Variable&Function #
  12. #----------------------------------------------------------#
  13. # Argument defenition
  14. type=$1
  15. host=$2
  16. port=$3
  17. dbuser=$4
  18. dbpass=$5
  19. max_db=${6-300}
  20. charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
  21. template=${8-template1}
  22. # Includes
  23. source $VESTA/conf/vesta.conf
  24. source $VESTA/func/shared.sh
  25. source $VESTA/func/db.sh
  26. #----------------------------------------------------------#
  27. # Verifications #
  28. #----------------------------------------------------------#
  29. args_usage='type host port dbuser dbpass [max_db] [charsets] [tpl]'
  30. check_args '5' "$#" "$args_usage"
  31. validate_format 'host' 'port' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
  32. is_system_enabled "$DB_SYSTEM"
  33. is_type_valid "$DB_SYSTEM" "$type"
  34. is_dbhost_new
  35. case $type in
  36. mysql) is_mysql_host_alive ;;
  37. pgsql) is_pgsql_host_alive ;;
  38. esac
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Concatentating db host string
  43. case $type in
  44. mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
  45. str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS='' ";
  46. str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'";;
  47. pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
  48. str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
  49. str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
  50. str="$str TIME='$TIME' DATE='$DATE'";;
  51. esac
  52. # Adding host to conf
  53. echo "$str" >> $VESTA/conf/$type.conf
  54. chmod 660 $VESTA/conf/$type.conf
  55. #----------------------------------------------------------#
  56. # Vesta #
  57. #----------------------------------------------------------#
  58. # Hiding password
  59. EVENT="DATE='$DATE' TIME='$TIME' COMMAND='$SCRIPT'"
  60. EVENT="$EVENT ARGUMENTS='$type $host $port $dbuser ****** $max_db $charsets"
  61. EVENT="$EVENT $tpl'"
  62. # Logging
  63. log_event "$OK" "$EVENT"
  64. exit