#!/usr/bin/env bash # start_workers.sh — dev launcher. session manager first, then the stateless workers, # each a uvicorn process in its own tmux window. production uses the systemd units in systemd/. set -euo pipefail cd "$(dirname "$0")" APP_DIR="$PWD" VENV="$APP_DIR/.venv/bin/activate" # MIOpen (ROCm): persist tuned kernels + FAST find so identity/tts don't re-auto-tune the GPU # on every start (that thrashed the CPU and stuttered Hyprland). FIND_ENFORCE forces exhaustive # search even when cached -> keep it unset. mkdir -p "$HOME/.config/miopen" MIOPEN_ENV="export MIOPEN_USER_DB_PATH=$HOME/.config/miopen MIOPEN_SYSTEM_DB_PATH=$HOME/.config/miopen MIOPEN_FIND_MODE=2 && unset MIOPEN_FIND_ENFORCE" SESSION="manga-workers" # name:module:port (session_manager guards the GPU; workers wait for it to bind) WORKERS=( "session:session_manager:8095" "crop:worker_crop:8000" "vision:worker_vision:8002" "identity:worker_identity:8003" "scene:worker_scene:8004" "script:worker_script:8005" "tts:worker_tts:8006" "layers:worker_layers:8007" "render:worker_render:8008" ) tmux kill-session -t "$SESSION" 2>/dev/null || true tmux new-session -d -s "$SESSION" -n placeholder for spec in "${WORKERS[@]}"; do name="${spec%%:*}"; rest="${spec#*:}"; mod="${rest%%:*}"; port="${rest##*:}" tmux new-window -t "$SESSION" -n "$name" tmux send-keys -t "$SESSION:$name" \ "$MIOPEN_ENV && source $VENV && python -m uvicorn ${mod}:app --app-dir $APP_DIR --host 0.0.0.0 --port ${port}" C-m if [ "$name" = "session" ]; then # workers assume the session manager is up; wait for :8095 before launching the rest until curl -sf http://127.0.0.1:8095/session/active >/dev/null 2>&1; do sleep 0.3; done fi done tmux kill-window -t "$SESSION:placeholder" 2>/dev/null || true echo "started ${#WORKERS[@]} processes in tmux session '$SESSION' (attach: tmux attach -t $SESSION)"