No Description

run-combined-stack.sh 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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 [[ $# -eq 0 ]]; then
  11. COMMAND="up"
  12. ARGS=(-d)
  13. else
  14. COMMAND="$1"
  15. shift
  16. ARGS=("$@")
  17. fi
  18. if [[ "${COMMAND}" == "help" || "${COMMAND}" == "--help" || "${COMMAND}" == "-h" ]]; then
  19. cat <<'EOF'
  20. Usage:
  21. ./run-combined-stack.sh [command] [target] [options]
  22. Commands:
  23. up Start services (default: up -d when no args)
  24. down Stop services (requires explicit target)
  25. logs View logs
  26. status Show container and endpoint status
  27. help Show this help message
  28. Targets:
  29. all|--all All stacks (wazuh, iris, shuffle, pagerduty, integrator, flask-openapi-shuffle)
  30. wazuh Wazuh single-node stack
  31. iris IRIS-web stack
  32. shuffle Shuffle stack
  33. pagerduty PagerDuty stub
  34. integrator SOC integrator stack
  35. flask-openapi-shuffle Flask OpenAPI demo stack
  36. Examples:
  37. ./run-combined-stack.sh
  38. ./run-combined-stack.sh up --all -d
  39. ./run-combined-stack.sh up iris -d
  40. ./run-combined-stack.sh up flask-openapi-shuffle -d
  41. ./run-combined-stack.sh down shuffle
  42. ./run-combined-stack.sh down --all
  43. ./run-combined-stack.sh logs integrator -f
  44. ./run-combined-stack.sh logs --all --tail 200
  45. ./run-combined-stack.sh status
  46. EOF
  47. exit 0
  48. fi
  49. if [[ "${COMMAND}" != "help" && "${COMMAND}" != "--help" && "${COMMAND}" != "-h" ]]; then
  50. if ! docker network inspect "${SOC_SHARED_NETWORK}" >/dev/null 2>&1; then
  51. docker network create "${SOC_SHARED_NETWORK}" >/dev/null
  52. fi
  53. fi
  54. if [[ "${COMMAND}" == "status" ]]; then
  55. exec "${ROOT_DIR}/soc-status.sh"
  56. fi
  57. run_wazuh() {
  58. docker compose \
  59. --project-name wazuh-single \
  60. --project-directory "${ROOT_DIR}/wazuh-docker/single-node" \
  61. -f "${ROOT_DIR}/wazuh-docker/single-node/docker-compose.yml" \
  62. -f "${ROOT_DIR}/compose-overrides/wazuh.shared-network.yml" \
  63. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  64. }
  65. run_iris() {
  66. docker compose \
  67. --project-name iris-web \
  68. --project-directory "${ROOT_DIR}/iris-web" \
  69. -f "${ROOT_DIR}/iris-web/docker-compose.yml" \
  70. -f "${ROOT_DIR}/compose-overrides/iris.shared-network.yml" \
  71. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  72. }
  73. run_shuffle() {
  74. docker compose \
  75. --project-name shuffle \
  76. --project-directory "${ROOT_DIR}/Shuffle" \
  77. -f "${ROOT_DIR}/Shuffle/docker-compose.yml" \
  78. -f "${ROOT_DIR}/compose-overrides/shuffle.shared-network.yml" \
  79. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  80. }
  81. run_pagerduty_stub() {
  82. docker compose \
  83. --project-name pagerduty-stub \
  84. --project-directory "${ROOT_DIR}" \
  85. -f "${ROOT_DIR}/compose-overrides/pagerduty.stub.yml" \
  86. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  87. }
  88. run_soc_integrator() {
  89. docker compose \
  90. --project-name soc-integrator \
  91. --project-directory "${ROOT_DIR}/compose-overrides" \
  92. -f "${ROOT_DIR}/compose-overrides/soc-integrator.yml" \
  93. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  94. }
  95. run_flask_openapi_shuffle() {
  96. docker compose \
  97. --project-name flask-openapi-shuffle \
  98. --project-directory "${ROOT_DIR}/flask-openapi-shuffle" \
  99. -f "${ROOT_DIR}/flask-openapi-shuffle/docker-compose.yml" \
  100. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  101. }
  102. run_target() {
  103. local target="$1"
  104. case "${target}" in
  105. wazuh)
  106. run_wazuh
  107. ;;
  108. iris)
  109. run_iris
  110. ;;
  111. shuffle)
  112. run_shuffle
  113. ;;
  114. pagerduty)
  115. run_pagerduty_stub
  116. ;;
  117. integrator)
  118. run_soc_integrator
  119. ;;
  120. flask-openapi-shuffle)
  121. run_flask_openapi_shuffle
  122. ;;
  123. *)
  124. echo "Unknown target: ${target}"
  125. echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator, flask-openapi-shuffle"
  126. exit 1
  127. ;;
  128. esac
  129. }
  130. run_all() {
  131. local mode="$1"
  132. if [[ "${mode}" == "down" ]]; then
  133. run_flask_openapi_shuffle
  134. run_soc_integrator
  135. run_pagerduty_stub
  136. run_shuffle
  137. run_iris
  138. run_wazuh
  139. else
  140. run_wazuh
  141. run_iris
  142. run_shuffle
  143. run_pagerduty_stub
  144. run_soc_integrator
  145. run_flask_openapi_shuffle
  146. fi
  147. }
  148. follow_all_logs() {
  149. COMMAND="logs"
  150. ARGS=("-f" "--tail" "${LOG_TAIL:-100}")
  151. run_wazuh &
  152. run_iris &
  153. run_shuffle &
  154. run_pagerduty_stub &
  155. run_soc_integrator &
  156. run_flask_openapi_shuffle &
  157. trap 'kill 0' INT TERM
  158. wait
  159. }
  160. run_logs_for_target() {
  161. local target="${1:-all}"
  162. case "${target}" in
  163. wazuh)
  164. run_wazuh
  165. ;;
  166. iris)
  167. run_iris
  168. ;;
  169. shuffle)
  170. run_shuffle
  171. ;;
  172. pagerduty)
  173. run_pagerduty_stub
  174. ;;
  175. integrator)
  176. run_soc_integrator
  177. ;;
  178. flask-openapi-shuffle)
  179. run_flask_openapi_shuffle
  180. ;;
  181. all|--all)
  182. run_wazuh
  183. run_iris
  184. run_shuffle
  185. run_pagerduty_stub
  186. run_soc_integrator
  187. run_flask_openapi_shuffle
  188. ;;
  189. *)
  190. echo "Unknown logs target: ${target}"
  191. echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator, flask-openapi-shuffle"
  192. exit 1
  193. ;;
  194. esac
  195. }
  196. if [[ "${COMMAND}" == "down" ]]; then
  197. TARGET="${1:-}"
  198. if [[ -z "${TARGET}" ]]; then
  199. echo "Refusing to run 'down' without a target."
  200. echo "Use one of:"
  201. echo " ./run-combined-stack.sh down <wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle>"
  202. echo " ./run-combined-stack.sh down --all"
  203. exit 1
  204. fi
  205. case "${TARGET}" in
  206. wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle)
  207. ARGS=("${ARGS[@]:1}")
  208. run_target "${TARGET}"
  209. ;;
  210. all|--all)
  211. ARGS=("${ARGS[@]:1}")
  212. run_all "down"
  213. ;;
  214. *)
  215. run_all "down"
  216. ;;
  217. esac
  218. elif [[ "${COMMAND}" == "logs" ]]; then
  219. LOGS_TARGET="${1:-all}"
  220. case "${LOGS_TARGET}" in
  221. wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle)
  222. ARGS=("${ARGS[@]:1}")
  223. run_logs_for_target "${LOGS_TARGET}"
  224. ;;
  225. all|--all)
  226. ARGS=("${ARGS[@]:1}")
  227. run_logs_for_target "all"
  228. ;;
  229. *)
  230. for arg in ${ARGS[@]+"${ARGS[@]}"}; do
  231. if [[ "${arg}" == "-f" || "${arg}" == "--follow" ]]; then
  232. echo "For follow mode, specify one target:"
  233. echo "./run-combined-stack.sh logs <wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle> -f"
  234. exit 1
  235. fi
  236. done
  237. run_logs_for_target "all"
  238. ;;
  239. esac
  240. elif [[ "${COMMAND}" == "up" ]]; then
  241. TARGET="${1:-all}"
  242. case "${TARGET}" in
  243. wazuh|iris|shuffle|pagerduty|integrator|flask-openapi-shuffle)
  244. ARGS=("${ARGS[@]:1}")
  245. run_target "${TARGET}"
  246. ;;
  247. all|--all)
  248. ARGS=("${ARGS[@]:1}")
  249. HAS_DETACH="false"
  250. for arg in ${ARGS[@]+"${ARGS[@]}"}; do
  251. if [[ "${arg}" == "-d" || "${arg}" == "--detach" ]]; then
  252. HAS_DETACH="true"
  253. break
  254. fi
  255. done
  256. if [[ "${HAS_DETACH}" == "true" ]]; then
  257. run_all "up"
  258. else
  259. ARGS+=("-d")
  260. run_all "up"
  261. follow_all_logs
  262. fi
  263. ;;
  264. *)
  265. run_all "up"
  266. ;;
  267. esac
  268. else
  269. run_all "up"
  270. fi