v_add_db_host 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/bin/bash
  2. # info: adding data base server
  3. #----------------------------------------------------------#
  4. # Variable&Function #
  5. #----------------------------------------------------------#
  6. # Argument defenition
  7. type="$1"
  8. host="$2"
  9. port="$3"
  10. db_user="$4"
  11. db_password="$5"
  12. max_usr="${6-300}"
  13. max_db="${7-300}"
  14. template="${8-template1}"
  15. # Importing variables
  16. source $VESTA/conf/vars.conf
  17. source $V_FUNC/shared_func.sh
  18. source $V_FUNC/db_func.sh
  19. #----------------------------------------------------------#
  20. # Verifications #
  21. #----------------------------------------------------------#
  22. # Checking arg number
  23. args_usage='type host port db_user db_password [max_usr] [max_db] [tpl]'
  24. check_args '5' "$#" "$args_usage"
  25. # Checking argument format
  26. format_validation 'host' 'port' 'db_user' 'db_password' 'max_usr' 'max_db'
  27. format_validation 'template'
  28. # Checking db system is enabled
  29. is_system_enabled 'db'
  30. # Checking db type
  31. is_type_valid 'db' "$type"
  32. # Checking host existance
  33. is_db_host_new
  34. # Checking host connection
  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) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
  45. new_str="$new_str PORT='$port' MAX_USERS='$max_usr'";
  46. new_str="$new_str MAX_DB='$max_db' U_SYS_USERS=''";
  47. new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
  48. pgsql) new_str="HOST='$host' USER='$db_user' PASSWORD='$db_password'";
  49. new_str="$new_str PORT='$port' TPL='$template'";
  50. new_str="$new_str MAX_USERS='$max_usr' MAX_DB='$max_db'";
  51. new_str="$new_str U_SYS_USERS=''";
  52. new_str="$new_str U_DB_BASES='0' ACTIVE='yes' DATE='$V_DATE'";;
  53. esac
  54. # Adding host to conf
  55. echo "$new_str" >> $V_DB/$type.conf
  56. chmod 650 $V_DB/$type.conf
  57. #----------------------------------------------------------#
  58. # Vesta #
  59. #----------------------------------------------------------#
  60. # Hidding db pass
  61. V_EVENT=$(echo $V_EVENT | sed -e "s/$db_password/xxxxxx/g")
  62. # Logging
  63. log_event 'system' "$V_EVENT"
  64. exit $OK