#!/bin/bash # StemeDB cluster entrypoint — runs both stemedb-api (storage) and stemedb-node (gateway/SWIM). # # In single-node mode (STEMEDB_CLUSTER_MODE unset or "false"), only stemedb-api runs. # In cluster mode (STEMEDB_CLUSTER_MODE=true), both binaries run side-by-side. set -e CLUSTER_MODE="${STEMEDB_CLUSTER_MODE:-false}" if [ "$CLUSTER_MODE" = "true" ] || [ "$CLUSTER_MODE" = "1" ]; then echo "Starting StemeDB in cluster mode" # Start stemedb-api in background (storage engine on :18180) stemedb-api & API_PID=$! # Wait briefly for API to bind before starting the gateway sleep 1 # Start stemedb-node in foreground (gateway :18181, gRPC :18182, SWIM :18183) stemedb-node & NODE_PID=$! # Trap signals to shut down both processes trap 'kill $API_PID $NODE_PID 2>/dev/null; wait' TERM INT # Wait for either process to exit — if one dies, kill both wait -n $API_PID $NODE_PID 2>/dev/null || true EXIT_CODE=$? kill $API_PID $NODE_PID 2>/dev/null || true wait exit $EXIT_CODE else echo "Starting StemeDB in single-node mode" exec stemedb-api "$@" fi