Miroslav Zagorac | 70230c6 | 2020-12-09 16:54:31 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | _ARG_HAPROXY="${1:-$(realpath -L ${PWD}/../../../haproxy)}" |
| 4 | _ARGS_FE="-f fe/haproxy.cfg" |
| 5 | _ARGS_BE="-f be/haproxy.cfg" |
| 6 | _TIME="$(date +%s)" |
| 7 | _LOG_DIR="_logs" |
| 8 | _LOG_FE="${_LOG_DIR}/_log-$(basename ${0} fe-be.sh)fe-${_TIME}" |
| 9 | _LOG_BE="${_LOG_DIR}/_log-$(basename ${0} fe-be.sh)be-${_TIME}" |
| 10 | |
| 11 | |
| 12 | __exit () |
| 13 | { |
| 14 | test -z "${2}" && { |
| 15 | echo |
| 16 | echo "Script killed!" |
| 17 | |
| 18 | echo "Waiting for jobs to complete..." |
| 19 | pkill --signal SIGUSR1 haproxy |
| 20 | wait |
| 21 | } |
| 22 | |
| 23 | test -n "${1}" && { |
| 24 | echo |
| 25 | echo "${1}" |
| 26 | echo |
| 27 | } |
| 28 | |
| 29 | exit ${2:-100} |
| 30 | } |
| 31 | |
| 32 | |
| 33 | trap __exit INT TERM |
| 34 | |
| 35 | test -x "${_ARG_HAPROXY}" || __exit "${_ARG_HAPROXY}: executable does not exist" 1 |
| 36 | mkdir -p "${_LOG_DIR}" || __exit "${_ARG_HAPROXY}: cannot create log directory" 2 |
| 37 | |
| 38 | echo "\n------------------------------------------------------------------------" |
| 39 | echo "--- executing: ${_ARG_HAPROXY} ${_ARGS_BE} > ${_LOG_BE}" |
| 40 | "${_ARG_HAPROXY}" ${_ARGS_BE} >"${_LOG_BE}" 2>&1 & |
| 41 | |
| 42 | echo "--- executing: ${_ARG_HAPROXY} ${_ARGS_FE} > ${_LOG_FE}" |
| 43 | "${_ARG_HAPROXY}" ${_ARGS_FE} >"${_LOG_FE}" 2>&1 & |
| 44 | echo "------------------------------------------------------------------------\n" |
| 45 | |
| 46 | echo "Press CTRL-C to quit..." |
| 47 | wait |