v_add_database_server 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. A5='******'
  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/main.sh
  25. source $VESTA/func/db.sh
  26. # Hiding password
  27. max_db=${6-500}
  28. #----------------------------------------------------------#
  29. # Verifications #
  30. #----------------------------------------------------------#
  31. args_usage='type host port dbuser dbpass [max_db] [charsets] [tpl]'
  32. check_args '5' "$#" "$args_usage"
  33. validate_format 'host' 'port' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
  34. is_system_enabled "$DB_SYSTEM"
  35. is_type_valid "$DB_SYSTEM" "$type"
  36. is_dbhost_new
  37. case $type in
  38. mysql) is_mysql_host_alive ;;
  39. pgsql) is_pgsql_host_alive ;;
  40. esac
  41. #----------------------------------------------------------#
  42. # Action #
  43. #----------------------------------------------------------#
  44. # Concatentating db host string
  45. case $type in
  46. mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
  47. str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS='' ";
  48. str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'";;
  49. pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass' PORT='$port'";
  50. str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
  51. str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
  52. str="$str TIME='$TIME' DATE='$DATE'";;
  53. esac
  54. # Adding host to conf
  55. echo "$str" >> $VESTA/conf/$type.conf
  56. chmod 660 $VESTA/conf/$type.conf
  57. #----------------------------------------------------------#
  58. # Vesta #
  59. #----------------------------------------------------------#
  60. # Logging
  61. log_history "added $type database server $host" '' 'admin'
  62. log_event "$OK" "$EVENT"
  63. exit