v_add_db_base 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/bash
  2. # info: add database
  3. # options: user db db_user db_password type [host] [encoding]
  4. #
  5. # The function creates the database concatenating username and user_db.
  6. # Supported yypes of databases you can get using v_list_sys_config script.
  7. # If the host isn't stated and there are few hosts configured on the server,
  8. # then the host will be defined by one of three algorithms. "First" will choose
  9. # the first host in the list. "Random" will chose the host by a chance.
  10. # "Weight" will distribute new database through hosts evenly. Algorithm and
  11. # types of supported databases is designated in the main configuration file.
  12. #----------------------------------------------------------#
  13. # Variable&Function #
  14. #----------------------------------------------------------#
  15. # Argument defenition
  16. user=$1
  17. database="$user"_"$2"
  18. db_user="$user"_"$3"
  19. db_password=$4
  20. type=$5
  21. host=$6
  22. encoding=${7-UTF8}
  23. # Importing variables
  24. source $VESTA/conf/vars.conf
  25. source $V_CONF/vesta.conf
  26. source $V_FUNC/shared.func
  27. source $V_FUNC/db.func
  28. #----------------------------------------------------------#
  29. # Verifications #
  30. #----------------------------------------------------------#
  31. # Checking arg number
  32. check_args '5' "$#" 'user db db_user db_password type [host] [encoding]'
  33. # Checking argument format
  34. format_validation 'user' 'database' 'db_user' 'db_password' 'encoding'
  35. # Checking db system is enabled
  36. is_system_enabled 'db'
  37. # Checking db type
  38. is_type_valid 'db' "$type"
  39. # Checking user
  40. is_user_valid
  41. # Checking user is active
  42. is_user_suspended
  43. # Checking db existance
  44. is_db_new
  45. # Checking db host
  46. if [ -z "$host" ]; then
  47. host=$(get_next_db_host)
  48. fi
  49. is_db_host_valid
  50. # Checking package
  51. is_package_full 'db_base'
  52. #----------------------------------------------------------#
  53. # Action #
  54. #----------------------------------------------------------#
  55. # Switching on db type
  56. case $type in
  57. mysql) create_db_mysql ;;
  58. pgsql) create_db_pgsql ;;
  59. esac
  60. #----------------------------------------------------------#
  61. # Vesta #
  62. #----------------------------------------------------------#
  63. # Increasing db value
  64. increase_db_value
  65. # Increasing domain value
  66. increase_user_value "$user" '$U_DATABASES'
  67. # Adding db to db conf
  68. v_str="DB='$database' USER='$db_user' HOST='$host' TYPE='$type'"
  69. v_str="$v_str U_DISK='0' SUSPEND='no' DATE='$V_DATE'"
  70. echo "$v_str">>$V_USERS/$user/db.conf
  71. # Hiding password
  72. V_EVENT="$V_DATE $V_SCRIPT $user $database $db_user ***** $type $host"
  73. # Logging
  74. log_history "$V_EVENT" "v_delete_db_base $user $database"
  75. log_event 'system' "$V_EVENT"
  76. exit