A lightweight Python-based process manager designed for Docker containers.
- Python 3.12+ – no external dependencies
Standard Python installation; you can build a wheel, and then run carnival directly.
For development, use uv run carnival.
Configured via TOML file (can be set on the command line or via CARNIVAL_CONFIG_TOML env var).
[[init]]
# Initialization commands (run sequentially)
command = "mkdir"
args = ["-p", "${DATA_DIR:-/data}"]
[[service]]
# Service definitions (run in parallel)
name = "webserver"
command = "python3"
args = ["-m", "http.server", "${PORT:-8000}"]
replicas = "${NUM_WORKERS:-2}"
restart = "always"
restart-delay-ms = "${RESTART_DELAY:-1000}" # or restart_delay_ms
restart-limit = 0 # 0 = unlimited (default); or restart_limit
stop-timeout-ms = 10000 # How long to give the process before SIGKILLing; or stop_timeout_msNote: Field names accept both kebab-case and snake_case.
Carnival supports environment variable interpolation in all string and numeric fields:
${VAR}- Uses value from environment, or preserves${VAR}if not set (for runtime expansion)${VAR:-default}- Uses value from environment, or usesdefaultif not set$VAR- Uses value from environment, or preserves$VARif not set (for runtime expansion)
Important: Variables not set at config parse time are preserved for runtime expansion by the shell. This allows you to reference CARNIVAL_* variables in your commands:
[[service]]
name = "worker"
command = "sh"
args = ["-c", "echo \"I am $CARNIVAL_SERVICE_NAME replica $CARNIVAL_REPLICA_ID\""]Numeric fields (replicas, restart_delay_ms) can also use environment variables:
- Accept both integer literals:
replicas = 3 - Or expandable strings:
replicas = "${NUM_WORKERS:-2}"
no- Run once, don't restart (one-shot tasks)always- Always restart, regardless of exit codeon-failure- Only restart on non-zero exit codes
Set restart_limit = N to limit the number of restarts. The service will run initially, then restart up to N-1 times (for a total of N runs). Default is 0 (unlimited restarts).
Set replicas = N to run N copies of a service. Each replica runs independently with its own restart counter.
Each service process automatically receives these environment variables:
CARNIVAL_SERVICE_NAME- The service name from the configCARNIVAL_REPLICA_ID- Zero-based replica index (0 to N-1)CARNIVAL_REPLICA_COUNT- Total number of replicas for this serviceCARNIVAL_RESTART_COUNT- Number of times this service has been restarted (starts at 0)
See examples/ for a complete working example.
MIT