v-add-web-domain-backend 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/bash
  2. # info: add web domain backend
  3. # options: USER DOMAIN [TEMPLATE] [RESTART]
  4. #
  5. # The call is used for adding web backend configuration.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument definition
  10. user=$1
  11. domain=$2
  12. template=${3-default}
  13. restart=$4
  14. # Includes
  15. source $HESTIA/func/main.sh
  16. source $HESTIA/func/domain.sh
  17. source $HESTIA/conf/hestia.conf
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [RESTART]'
  22. is_format_valid 'user' 'domain'
  23. is_system_enabled "$WEB_BACKEND" 'WEB_BACKEND'
  24. is_object_valid 'user' 'USER' "$user"
  25. is_object_unsuspended 'user' 'USER' "$user"
  26. is_backend_template_valid "$template"
  27. #----------------------------------------------------------#
  28. # Action #
  29. #----------------------------------------------------------#
  30. # Defining pool directory
  31. prepare_web_backend
  32. # Checking backend configuration
  33. if [ -e "$pool/$backend_type.conf" ]; then
  34. exit
  35. fi
  36. # Allocating backend port
  37. backend_port=9000
  38. ports=$(grep -v '^;' $pool/* 2>/dev/null |grep listen |grep -o :[0-9].*)
  39. ports=$(echo "$ports" |sed "s/://" |sort -n)
  40. for port in $ports; do
  41. if [ "$backend_port" -eq "$port" ]; then
  42. backend_port=$((backend_port + 1))
  43. fi
  44. done
  45. # Adding backend config
  46. cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
  47. sed -e "s|%backend_port%|$backend_port|" \
  48. -e "s|%user%|$user|g"\
  49. -e "s|%domain%|$domain|g"\
  50. -e "s|%backend%|$backend_type|g" > $pool/$backend_type.conf
  51. #----------------------------------------------------------#
  52. # Hestia #
  53. #----------------------------------------------------------#
  54. # Restart backend server
  55. $BIN/v-restart-web-backend $restart
  56. check_result $? "Web backend restart failed" >/dev/null
  57. # Logging
  58. log_history "added $WEB_BACKEND backend configuration for $domain"
  59. log_event "$OK" "$ARGUMENTS"
  60. exit