CreateProxyProcess 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env bash
  2. # shellcheck shell=bash
  3. # ``````````````````````````````````````````````````````````````````````````````
  4. # Function name: CreateProxyProcess()
  5. #
  6. # Description:
  7. # It creates tor load balancer with haproxy.
  8. #
  9. # Usage:
  10. # CreateProxyProcess
  11. #
  12. # Examples:
  13. # CreateProxyProcess
  14. #
  15. function CreateProxyProcess() {
  16. # shellcheck disable=SC2034
  17. local _FUNCTION_ID="CreateProxyProcess"
  18. local _STATE=0
  19. # Port number from HAProxy config file.
  20. local _bk_port_tmp="16379"
  21. local _bk_port_new=0
  22. # shellcheck disable=SC2154
  23. for _bk_port in "${_proxy_ports[@]}" ; do
  24. if [[ "$proxy_state" -eq 1 ]] && \
  25. [[ ! "$frontend_type" == "haproxy" ]] ; then
  26. # shellcheck disable=SC2034
  27. _bk_port_new="$_bk_port"
  28. # shellcheck disable=SC2154
  29. printf " server socks-process-%d 127.0.0.1:%d check fall 3 rise 2\\n" "$_bk_port" "$_bk_port_new" \
  30. >>"${_tml_ha1}"
  31. _logger "info" \
  32. "${_FUNCTION_ID}()" \
  33. "added backend port (haproxy): '$_bk_port'"
  34. else
  35. # shellcheck disable=SC2034
  36. _bk_port_new=$((_bk_port_tmp - 1000))
  37. # shellcheck disable=SC2154
  38. printf " server %s-process-%d 127.0.0.1:%d check fall 3 rise 2\\n" "$proxy_type" "$_bk_port_new" "$_bk_port_new" \
  39. >>"${_tml_ha1}"
  40. _logger "info" \
  41. "${_FUNCTION_ID}()" \
  42. "added backend port (haproxy): '$_bk_port_new'"
  43. CreateWebProxyProcess
  44. _bk_port_tmp=$((_bk_port_tmp + 1))
  45. fi
  46. done
  47. if [[ ! "$frontend_type" == "haproxy" ]] ; then
  48. # Port number from HAProxy config file.
  49. # shellcheck disable=SC2034
  50. _bk_port="16379"
  51. _bk_port_new=$((_bk_port - 1000))
  52. CreateWebProxyProcess
  53. fi
  54. # shellcheck disable=SC2154
  55. # Init HAProxy process.
  56. haproxy -f "${_tml_ha1}" && \
  57. _logger "info" \
  58. "${_FUNCTION_ID}()" \
  59. "init proxy process with '${_tml_ha1}' config file"
  60. return $_STATE
  61. }