v-add-web-domain-backend 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 $VESTA/func/main.sh
  16. source $VESTA/func/domain.sh
  17. source $VESTA/conf/vesta.conf
  18. #----------------------------------------------------------#
  19. # Verifications #
  20. #----------------------------------------------------------#
  21. check_args '2' "$#" 'USER DOMAIN [TEMPLATE] [RESTART]'
  22. is_system_enabled "$WEB_BACKEND" 'WEB_BACKEND'
  23. is_object_valid 'user' 'USER' "$user"
  24. is_object_unsuspended 'user' 'USER' "$user"
  25. is_backend_template_valid "$template"
  26. #----------------------------------------------------------#
  27. # Action #
  28. #----------------------------------------------------------#
  29. # Defining pool directory
  30. prepare_web_backend
  31. # Checking backend configuration
  32. if [ -e "$pool/$backend_type.conf" ]; then
  33. exit
  34. fi
  35. # Allocating backend port
  36. backend_port=9000
  37. ports=$(grep -v '^;' $pool/* 2>/dev/null |grep listen |grep -o :[0-9].*)
  38. ports=$(echo "$ports" |sed "s/://" |sort -n)
  39. for port in $ports; do
  40. if [ "$backend_port" -eq "$port" ]; then
  41. backend_port=$((backend_port + 1))
  42. fi
  43. done
  44. # Adding backend config
  45. cat $WEBTPL/$WEB_BACKEND/$template.tpl |\
  46. sed -e "s|%backend_port%|$backend_port|" \
  47. -e "s|%user%|$user|"\
  48. -e "s|%domain%|$domain|"\
  49. -e "s|%backend%|$backend_type|g" > $pool/$backend_type.conf
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. # Restart backend server
  54. $BIN/v-restart-web-backend $restart
  55. check_result $? "Web backend restart failed" >/dev/null
  56. # Logging
  57. log_history "added $WEB_BACKEND backend configuration for $domain"
  58. log_event "$OK" "$ARGUMENTS"
  59. exit