Geen omschrijving

run-combined-stack.sh 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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
  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)
  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. Examples:
  36. ./run-combined-stack.sh
  37. ./run-combined-stack.sh up --all -d
  38. ./run-combined-stack.sh up iris -d
  39. ./run-combined-stack.sh down shuffle
  40. ./run-combined-stack.sh logs integrator -f
  41. ./run-combined-stack.sh logs --all --tail 200
  42. ./run-combined-stack.sh status
  43. EOF
  44. exit 0
  45. fi
  46. if [[ "${COMMAND}" != "help" && "${COMMAND}" != "--help" && "${COMMAND}" != "-h" ]]; then
  47. if ! docker network inspect "${SOC_SHARED_NETWORK}" >/dev/null 2>&1; then
  48. docker network create "${SOC_SHARED_NETWORK}" >/dev/null
  49. fi
  50. fi
  51. if [[ "${COMMAND}" == "status" ]]; then
  52. exec "${ROOT_DIR}/soc-status.sh"
  53. fi
  54. run_wazuh() {
  55. docker compose \
  56. --project-name wazuh-single \
  57. --project-directory "${ROOT_DIR}/wazuh-docker/single-node" \
  58. -f "${ROOT_DIR}/wazuh-docker/single-node/docker-compose.yml" \
  59. -f "${ROOT_DIR}/compose-overrides/wazuh.shared-network.yml" \
  60. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  61. }
  62. run_iris() {
  63. docker compose \
  64. --project-name iris-web \
  65. --project-directory "${ROOT_DIR}/iris-web" \
  66. -f "${ROOT_DIR}/iris-web/docker-compose.yml" \
  67. -f "${ROOT_DIR}/compose-overrides/iris.shared-network.yml" \
  68. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  69. }
  70. run_shuffle() {
  71. docker compose \
  72. --project-name shuffle \
  73. --project-directory "${ROOT_DIR}/Shuffle" \
  74. -f "${ROOT_DIR}/Shuffle/docker-compose.yml" \
  75. -f "${ROOT_DIR}/compose-overrides/shuffle.shared-network.yml" \
  76. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  77. }
  78. run_pagerduty_stub() {
  79. docker compose \
  80. --project-name pagerduty-stub \
  81. --project-directory "${ROOT_DIR}" \
  82. -f "${ROOT_DIR}/compose-overrides/pagerduty.stub.yml" \
  83. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  84. }
  85. run_soc_integrator() {
  86. docker compose \
  87. --project-name soc-integrator \
  88. --project-directory "${ROOT_DIR}/compose-overrides" \
  89. -f "${ROOT_DIR}/compose-overrides/soc-integrator.yml" \
  90. "${COMMAND}" ${ARGS[@]+"${ARGS[@]}"}
  91. }
  92. run_target() {
  93. local target="$1"
  94. case "${target}" in
  95. wazuh)
  96. run_wazuh
  97. ;;
  98. iris)
  99. run_iris
  100. ;;
  101. shuffle)
  102. run_shuffle
  103. ;;
  104. pagerduty)
  105. run_pagerduty_stub
  106. ;;
  107. integrator)
  108. run_soc_integrator
  109. ;;
  110. *)
  111. echo "Unknown target: ${target}"
  112. echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator"
  113. exit 1
  114. ;;
  115. esac
  116. }
  117. run_all() {
  118. local mode="$1"
  119. if [[ "${mode}" == "down" ]]; then
  120. run_soc_integrator
  121. run_pagerduty_stub
  122. run_shuffle
  123. run_iris
  124. run_wazuh
  125. else
  126. run_wazuh
  127. run_iris
  128. run_shuffle
  129. run_pagerduty_stub
  130. run_soc_integrator
  131. fi
  132. }
  133. follow_all_logs() {
  134. COMMAND="logs"
  135. ARGS=("-f" "--tail" "${LOG_TAIL:-100}")
  136. run_wazuh &
  137. run_iris &
  138. run_shuffle &
  139. run_pagerduty_stub &
  140. run_soc_integrator &
  141. trap 'kill 0' INT TERM
  142. wait
  143. }
  144. run_logs_for_target() {
  145. local target="${1:-all}"
  146. case "${target}" in
  147. wazuh)
  148. run_wazuh
  149. ;;
  150. iris)
  151. run_iris
  152. ;;
  153. shuffle)
  154. run_shuffle
  155. ;;
  156. pagerduty)
  157. run_pagerduty_stub
  158. ;;
  159. integrator)
  160. run_soc_integrator
  161. ;;
  162. all|--all)
  163. run_wazuh
  164. run_iris
  165. run_shuffle
  166. run_pagerduty_stub
  167. run_soc_integrator
  168. ;;
  169. *)
  170. echo "Unknown logs target: ${target}"
  171. echo "Use one of: wazuh, iris, shuffle, pagerduty, integrator"
  172. exit 1
  173. ;;
  174. esac
  175. }
  176. if [[ "${COMMAND}" == "down" ]]; then
  177. TARGET="${1:-all}"
  178. case "${TARGET}" in
  179. wazuh|iris|shuffle|pagerduty|integrator)
  180. ARGS=("${ARGS[@]:1}")
  181. run_target "${TARGET}"
  182. ;;
  183. all|--all)
  184. ARGS=("${ARGS[@]:1}")
  185. run_all "down"
  186. ;;
  187. *)
  188. run_all "down"
  189. ;;
  190. esac
  191. elif [[ "${COMMAND}" == "logs" ]]; then
  192. LOGS_TARGET="${1:-all}"
  193. case "${LOGS_TARGET}" in
  194. wazuh|iris|shuffle|pagerduty|integrator)
  195. ARGS=("${ARGS[@]:1}")
  196. run_logs_for_target "${LOGS_TARGET}"
  197. ;;
  198. all|--all)
  199. ARGS=("${ARGS[@]:1}")
  200. run_logs_for_target "all"
  201. ;;
  202. *)
  203. for arg in ${ARGS[@]+"${ARGS[@]}"}; do
  204. if [[ "${arg}" == "-f" || "${arg}" == "--follow" ]]; then
  205. echo "For follow mode, specify one target:"
  206. echo "./run-combined-stack.sh logs <wazuh|iris|shuffle|pagerduty|integrator> -f"
  207. exit 1
  208. fi
  209. done
  210. run_logs_for_target "all"
  211. ;;
  212. esac
  213. elif [[ "${COMMAND}" == "up" ]]; then
  214. TARGET="${1:-all}"
  215. case "${TARGET}" in
  216. wazuh|iris|shuffle|pagerduty|integrator)
  217. ARGS=("${ARGS[@]:1}")
  218. run_target "${TARGET}"
  219. ;;
  220. all|--all)
  221. ARGS=("${ARGS[@]:1}")
  222. HAS_DETACH="false"
  223. for arg in ${ARGS[@]+"${ARGS[@]}"}; do
  224. if [[ "${arg}" == "-d" || "${arg}" == "--detach" ]]; then
  225. HAS_DETACH="true"
  226. break
  227. fi
  228. done
  229. if [[ "${HAS_DETACH}" == "true" ]]; then
  230. run_all "up"
  231. else
  232. ARGS+=("-d")
  233. run_all "up"
  234. follow_all_logs
  235. fi
  236. ;;
  237. *)
  238. run_all "up"
  239. ;;
  240. esac
  241. else
  242. run_all "up"
  243. fi