Repository navigation
Description
Problem
jiji stops containers with a bare docker stop <name> / podman stop <name> (crates/jiji-cli/src/container_ops.rs:222). Both engines default to a 10 second grace period after SIGTERM, then SIGKILL. A service whose graceful shutdown takes longer gets killed partway through, and there is no way to configure that.
This hits on every rolling deploy: the previous container is marked Draining and stopped right away (deploy_transaction.rs:305, :397, :584, :685, :791), as well as in service remove, service scale and server teardown through stop_if_running.
Concrete case: a background worker (BullMQ) that, on SIGTERM, stops taking jobs and waits for running ones to finish. A long import job can run for minutes, so each deploy kills it mid-job. It only recovers because the job is safe to retry, and it repeats work it had nearly finished.
Proposal
Add an optional per-service stop_timeout to the deploy config, next to stop_first in crates/jiji-config/src/schema.rs:
services:
worker:
stop_timeout: 5mApply it with --stop-timeout <seconds> when the container is created (container_runtime.rs), not only as stop -t at the call sites. Docker and Podman both support the flag. Set at creation, it covers every stop path, including ones jiji doesn't run itself, such as docker restart or the engine shutting down on host reboot (within the daemon's own shutdown timeout). Passing -t explicitly in container_ops::stop as well would make the value visible in jiji's own logs.
Details to decide
- Parse with the same duration format as the existing
timeoutanddeploy_timeoutfields. Omitted means the engine default, so current behaviour doesn't change. - Deploys wait on the old container's stop, so a long
stop_timeoutmakes the deploy take longer. That's expected for services that need it; worth a line in the docs. - Should the healthcheck
deploy_timeoutor any SSH command timeout be raised to allow forstop_timeout, so a long stop isn't mistaken for a hang?
Done when
stop_timeoutvalidates in the config schema and appears in the docs and the deploy.yml reference.- A container deployed with it reports the value in
docker inspect(.Config.StopTimeout) on both Docker and Podman. - A test covers the generated run command with and without the field.
Activity