8000 Add a per-service stop_timeout so slow graceful shutdowns aren't killed after 10s · Issue #138 · acidtib/jiji · GitHub
[go: up one dir, main page]

Skip to content

Add a per-service stop_timeout so slow graceful shutdowns aren't killed after 10s #138

Open

Description

@acidtib

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: 5m

Apply 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 timeout and deploy_timeout fields. Omitted means the engine default, so current behaviour doesn't change.
  • Deploys wait on the old container's stop, so a long stop_timeout makes the deploy take longer. That's expected for services that need it; worth a line in the docs.
  • Should the healthcheck deploy_timeout or any SSH command timeout be raised to allow for stop_timeout, so a long stop isn't mistaken for a hang?

Done when

  • stop_timeout validates 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

  1. added
    enhancement
    on Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0