Brak opisu

run-combined-stack.sh 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
  4. export SOC_SHARED_NETWORK="${SOC_SHARED_NETWORK:-soc_shared}"
  5. export IRIS_HTTPS_PORT="${IRIS_HTTPS_PORT:-8443}"
  6. export INTERFACE_HTTPS_PORT="${IRIS_HTTPS_PORT}"
  7. export SHUFFLE_OPENSEARCH_PORT="${SHUFFLE_OPENSEARCH_PORT:-9201}"
  8. export PAGERDUTY_STUB_PORT="${PAGERDUTY_STUB_PORT:-18080}"
  9. export SOC_INTEGRATOR_PORT="${SOC_INTEGRATOR_PORT:-8088}"
  10. if ! docker network inspect "${SOC_SHARED_NETWORK}" >/dev/null 2>&1; then
  11. docker network create "${SOC_SHARED_NETWORK}" >/dev/null
  12. fi
  13. if [[ $# -eq 0 ]]; then
  14. COMMAND="up"
  15. ARGS=(-d)
  16. else
  17. COMMAND="$1"
  18. shift
  19. ARGS=("$@")
  20. fi
  21. if [[ "${COMMAND}" == "status" ]]; then
  22. exec "${ROOT_DIR}/soc-status.sh"
  23. fi
  24. run_wazuh() {
  25. docker compose \
  26. --project-name wazuh-single \
  27. --project-directory "${ROOT_DIR}/wazuh-docker/single-node" \
  28. -f "${ROOT_DIR}/wazuh-docker/single-node/docker-compose.yml" \
  29. -f "${ROOT_DIR}/compose-overrides/wazuh.shared-network.yml" \
  30. "${COMMAND}" "${ARGS[@]}"
  31. }
  32. run_iris() {
  33. docker compose \
  34. --project-name iris-web \
  35. --project-directory "${ROOT_DIR}/iris-web" \
  36. -f "${ROOT_DIR}/iris-web/docker-compose.yml" \
  37. -f "${ROOT_DIR}/compose-overrides/iris.shared-network.yml" \
  38. "${COMMAND}" "${ARGS[@]}"
  39. }
  40. run_shuffle() {
  41. docker compose \
  42. --project-name shuffle \
  43. --project-directory "${ROOT_DIR}/Shuffle" \
  44. -f "${ROOT_DIR}/Shuffle/docker-compose.yml" \
  45. -f "${ROOT_DIR}/compose-overrides/shuffle.shared-network.yml" \
  46. "${COMMAND}" "${ARGS[@]}"
  47. }
  48. run_pagerduty_stub() {
  49. docker compose \
  50. --project-name pagerduty-stub \
  51. --project-directory "${ROOT_DIR}" \
  52. -f "${ROOT_DIR}/compose-overrides/pagerduty.stub.yml" \
  53. "${COMMAND}" "${ARGS[@]}"
  54. }
  55. run_soc_integrator() {
  56. docker compose \
  57. --project-name soc-integrator \
  58. --project-directory "${ROOT_DIR}/compose-overrides" \
  59. -f "${ROOT_DIR}/compose-overrides/soc-integrator.yml" \
  60. "${COMMAND}" "${ARGS[@]}"
  61. }
  62. run_target() {
  63. local target="$1"
  64. case "${target}" in
  65. wazuh)
  66. run_wazuh
  67. ;;
  68. iris)
  69. run_iris
  70. ;;
  71. shuffle)
  72. run_shuffle
  73. ;;
  74. pagerduty)
  75. run_pagerduty_stub
  76. ;;
  77. integrator)
  78. run_soc_integrator
  79. ;;
  80. *)
  81. echo "Unknown target: ${target}"
  82. echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator"
  83. exit 1
  84. ;;
  85. esac
  86. }
  87. run_all() {
  88. local mode="$1"
  89. if [[ "${mode}" == "down" ]]; then
  90. run_soc_integrator
  91. run_pagerduty_stub
  92. run_shuffle
  93. run_iris
  94. run_wazuh
  95. else
  96. run_wazuh
  97. run_iris
  98. run_shuffle
  99. run_pagerduty_stub
  100. run_soc_integrator
  101. fi
  102. }
  103. follow_all_logs() {
  104. COMMAND="logs"
  105. ARGS=("-f" "--tail" "${LOG_TAIL:-100}")
  106. run_wazuh &
  107. run_iris &
  108. run_shuffle &
  109. run_pagerduty_stub &
  110. run_soc_integrator &
  111. trap 'kill 0' INT TERM
  112. wait
  113. }
  114. run_logs_for_target() {
  115. local target="${1:-all}"
  116. case "${target}" in
  117. wazuh)
  118. run_wazuh
  119. ;;
  120. iris)
  121. run_iris
  122. ;;
  123. shuffle)
  124. run_shuffle
  125. ;;
  126. pagerduty)
  127. run_pagerduty_stub
  128. ;;
  129. integrator)
  130. run_soc_integrator
  131. ;;
  132. all|--all)
  133. run_wazuh
  134. run_iris
  135. run_shuffle
  136. run_pagerduty_stub
  137. run_soc_integrator
  138. ;;
  139. *)
  140. echo "Unknown logs target: ${target}"
  141. echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator"
  142. exit 1
  143. ;;
  144. esac
  145. }
  146. if [[ "${COMMAND}" == "down" ]]; then
  147. TARGET="${1:-all}"
  148. case "${TARGET}" in
  149. wazuh|iris|shuffle|pagerduty|integrator)
  150. ARGS=("${ARGS[@]:1}")
  151. run_target "${TARGET}"
  152. ;;
  153. all|--all)
  154. ARGS=("${ARGS[@]:1}")
  155. run_all "down"
  156. ;;
  157. *)
  158. run_all "down"
  159. ;;
  160. esac
  161. elif [[ "${COMMAND}" == "logs" ]]; then
  162. LOGS_TARGET="${1:-all}"
  163. case "${LOGS_TARGET}" in
  164. wazuh|iris|shuffle|pagerduty|integrator)
  165. ARGS=("${ARGS[@]:1}")
  166. run_logs_for_target "${LOGS_TARGET}"
  167. ;;
  168. all|--all)
  169. ARGS=("${ARGS[@]:1}")
  170. run_logs_for_target "all"
  171. ;;
  172. *)
  173. for arg in "${ARGS[@]}"; do
  174. if [[ "${arg}" == "-f" || "${arg}" == "--follow" ]]; then
  175. echo "For follow mode, specify one target:"
  176. echo "./run-combined-stack.sh logs <wazuh|iris|shuffle|pagerduty|integrator> -f"
  177. exit 1
  178. fi
  179. done
  180. run_logs_for_target "all"
  181. ;;
  182. esac
  183. elif [[ "${COMMAND}" == "up" ]]; then
  184. TARGET="${1:-all}"
  185. case "${TARGET}" in
  186. wazuh|iris|shuffle|pagerduty|integrator)
  187. ARGS=("${ARGS[@]:1}")
  188. run_target "${TARGET}"
  189. ;;
  190. all|--all)
  191. ARGS=("${ARGS[@]:1}")
  192. HAS_DETACH="false"
  193. for arg in "${ARGS[@]}"; do
  194. if [[ "${arg}" == "-d" || "${arg}" == "--detach" ]]; then
  195. HAS_DETACH="true"
  196. break
  197. fi
  198. done
  199. if [[ "${HAS_DETACH}" == "true" ]]; then
  200. run_all "up"
  201. else
  202. ARGS+=("-d")
  203. run_all "up"
  204. follow_all_logs
  205. fi
  206. ;;
  207. *)
  208. run_all "up"
  209. ;;
  210. esac
  211. else
  212. run_all "up"
  213. fi