[supervisord]
nodaemon=true
logfile=/app/data/logs/supervisord.log
logfile_maxbytes=10MB
logfile_backups=3
pidfile=/tmp/supervisord.pid

[unix_http_server]
file=/tmp/supervisor.sock

[supervisorctl]
serverurl=unix:///tmp/supervisor.sock

[rpcinterface:supervisor]
supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface

# ── Serviços base ────────────────────────────────────────────────────────────

[program:mediamtx]
command=/usr/local/bin/mediamtx /etc/mediamtx.yml
autorestart=true
priority=1
stdout_logfile=/app/data/logs/mediamtx.log
stderr_logfile=/app/data/logs/mediamtx.log

[program:nextjs]
directory=/app
command=node /opt/server.mjs
environment=PORT=3000,HOSTNAME=0.0.0.0,DATA_DIR=/app/data
autorestart=true
priority=2
stdout_logfile=/app/data/logs/nextjs.log
stderr_logfile=/app/data/logs/nextjs.log

# ── Streams dinâmicas ────────────────────────────────────────────────────────
# Cada stream gera /app/data/streams/{id}/stream.conf
# O supervisord inclui todos automaticamente

[program:novnc]
command=websockify --web /usr/share/novnc --target-config /app/data/vnc-tokens 6080
autorestart=true
priority=3
stdout_logfile=/app/data/logs/novnc.log
stderr_logfile=/app/data/logs/novnc.log

[program:restore-streams]
command=/opt/scripts/restore-streams.sh
autorestart=false
priority=4
stdout_logfile=/app/data/logs/restore.log
stderr_logfile=/app/data/logs/restore.log

[include]
files = /app/data/streams/*/stream.conf