#!/bin/sh # docker-entrypoint.sh — Polaris Task Force container entrypoint (PID 1). # Always starts the web server (CMD: node server.js, received as "$@"). # Starts the Discord bot (`bun run bot`) ONLY when DISCORD_TOKEN is set # (Coolify per-environment activation gate; dev/stage leave it unset). # Forwards SIGTERM/SIGINT to both children, reaps them, and exits with # the web server's exit status. "$@" & WEB_PID=$! BOT_PID="" if [ -n "${DISCORD_TOKEN:-}" ]; then echo "[entrypoint] DISCORD_TOKEN is set — starting Discord bot" >&2 bun run bot & BOT_PID=$! else echo "[entrypoint] DISCORD_TOKEN is not set — Discord bot disabled" >&2 fi forward() { signal=$1 [ -z "$WEB_PID" ] || kill -"$signal" "$WEB_PID" 2>/dev/null || true [ -z "$BOT_PID" ] || kill -"$signal" "$BOT_PID" 2>/dev/null || true } trap 'forward TERM' TERM trap 'forward INT' INT while kill -0 "$WEB_PID" 2>/dev/null; do wait "$WEB_PID" status=$? done if [ -n "$BOT_PID" ]; then kill -TERM "$BOT_PID" 2>/dev/null || true wait "$BOT_PID" 2>/dev/null || true fi exit "${status:-0}"