v-add-database-host 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # info: add new database server
  3. # options: TYPE HOST 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. dbuser=$3
  17. dbpass=$4
  18. max_db=${6-500}
  19. charsets=${7-UTF8,LATIN1,WIN1250,WIN1251,WIN1252,WIN1256,WIN1258,KOI8}
  20. template=${8-template1}
  21. # Includes
  22. source $VESTA/func/main.sh
  23. source $VESTA/func/db.sh
  24. source $VESTA/conf/vesta.conf
  25. # Hiding password
  26. A4='******'
  27. #----------------------------------------------------------#
  28. # Verifications #
  29. #----------------------------------------------------------#
  30. args_usage='TYPE HOST DBUSER DBPASS [MAX_DB] [CHARSETS] [TPL]'
  31. check_args '4' "$#" "$args_usage"
  32. validate_format 'host' 'dbuser' 'dbpass' 'max_db' 'charsets' 'template'
  33. is_system_enabled "$DB_SYSTEM" 'DB_SYSTEM'
  34. is_type_valid "$DB_SYSTEM" "$type"
  35. is_dbhost_new
  36. case $type in
  37. mysql) is_mysql_host_alive ;;
  38. pgsql) is_pgsql_host_alive ;;
  39. esac
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Concatentating db host string
  44. case $type in
  45. mysql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
  46. str="$str CHARSETS='$charsets' MAX_DB='$max_db' U_SYS_USERS=''";
  47. str="$str U_DB_BASES='0' SUSPENDED='no' TIME='$TIME' DATE='$DATE'";;
  48. pgsql) str="HOST='$host' USER='$dbuser' PASSWORD='$dbpass'";
  49. str="$str CHARSETS='$charsets' TPL='$template' MAX_DB='$max_db'";
  50. str="$str U_SYS_USERS='' U_DB_BASES='0' SUSPENDED='no'";
  51. str="$str TIME='$TIME' DATE='$DATE'";;
  52. esac
  53. # Adding host to conf
  54. echo "$str" >> $VESTA/conf/$type.conf
  55. chmod 660 $VESTA/conf/$type.conf
  56. #----------------------------------------------------------#
  57. # Vesta #
  58. #----------------------------------------------------------#
  59. # Logging
  60. log_event "$OK" "$EVENT"
  61. exit