diff --git a/README.md b/README.md index ebafb5da..42d540ec 100644 --- a/README.md +++ b/README.md @@ -347,6 +347,15 @@ logging: If nothing is configured, the default option `max-size=10m` is used for all containers. The default logging driver of Docker is `json-file`. +### Using a different stop wait time + +On a new deploy, each old running container is gracefully shut down with a `SIGTERM`, and after a grace period of `10` seconds a `SIGKILL` is sent. +You can configure this value via the `stop_wait_time` option: + +```yaml +stop_wait_time: 30 +``` + ### Using remote builder for native multi-arch If you're developing on ARM64 (like Apple Silicon), but you want to deploy on AMD64 (x86 64-bit), you can use multi-architecture images. By default, MRSK will setup a local buildx configuration that does this through QEMU emulation. But this can be quite slow, especially on the first build. diff --git a/lib/mrsk/commands/app.rb b/lib/mrsk/commands/app.rb index 02c41c81..f2064e74 100644 --- a/lib/mrsk/commands/app.rb +++ b/lib/mrsk/commands/app.rb @@ -30,7 +30,7 @@ class Mrsk::Commands::App < Mrsk::Commands::Base def stop(version: nil) pipe \ version ? container_id_for_version(version) : current_container_id, - xargs(docker(:stop)) + xargs(config.stop_wait_time ? docker(:stop, "-t", config.stop_wait_time) : docker(:stop)) end def info diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index f1f1ee91..aa4cd67e 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -6,7 +6,7 @@ require "erb" require "net/ssh/proxy/jump" class Mrsk::Configuration - delegate :service, :image, :servers, :env, :labels, :registry, :builder, :logging, to: :raw_config, allow_nil: true + delegate :service, :image, :servers, :env, :labels, :registry, :builder, :stop_wait_time, to: :raw_config, allow_nil: true delegate :argumentize, :argumentize_env_with_secrets, :optionize, to: Mrsk::Utils attr_accessor :destination diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index 0080c556..88459bf4 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -67,6 +67,13 @@ class CommandsAppTest < ActiveSupport::TestCase new_command.stop.join(" ") end + test "stop with custom stop wait time" do + @config[:stop_wait_time] = 30 + assert_equal \ + "docker ps --quiet --filter label=service=app --filter label=role=web | xargs docker stop -t 30", + new_command.stop.join(" ") + end + test "stop with version" do assert_equal \ "docker container ls --all --filter name=app-web-123 --quiet | xargs docker stop",