From 9b43a6b23b445606408efbf32ac059d0aaf4ba1d Mon Sep 17 00:00:00 2001 From: Jacopo Date: Fri, 24 Mar 2023 14:57:49 +0100 Subject: [PATCH] Customizable stop wait time Configurable via a global `stop_wait_time` option. The default is `10` which matches Docker defaults. --- README.md | 9 +++++++++ lib/mrsk/commands/app.rb | 4 +++- lib/mrsk/configuration.rb | 3 ++- test/commands/app_test.rb | 4 ++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1ffd09f1..24fd2328 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,15 @@ servers: That'll start the job containers with `docker run ... --cap-add --cpu-count 4 ...`. +### 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 9f9e987c..5d4d36d1 100644 --- a/lib/mrsk/commands/app.rb +++ b/lib/mrsk/commands/app.rb @@ -27,10 +27,12 @@ class Mrsk::Commands::App < Mrsk::Commands::Base docker :start, service_with_version_and_destination_and_role end + DEFAULT_STOP_WAIT_TIME = 10 + def stop(version: nil) pipe \ version ? container_id_for_version(version) : current_container_id, - xargs(docker(:stop)) + xargs(docker(:stop, "-t", config.stop_wait_time || DEFAULT_STOP_WAIT_TIME)) end def info diff --git a/lib/mrsk/configuration.rb b/lib/mrsk/configuration.rb index 71f56b37..a9f72afe 100644 --- a/lib/mrsk/configuration.rb +++ b/lib/mrsk/configuration.rb @@ -6,7 +6,8 @@ require "erb" require "net/ssh/proxy/jump" class Mrsk::Configuration - delegate :service, :image, :servers, :env, :labels, :registry, :builder, 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, to: Mrsk::Utils attr_accessor :destination diff --git a/test/commands/app_test.rb b/test/commands/app_test.rb index 2a18b9c6..26c6fa04 100644 --- a/test/commands/app_test.rb +++ b/test/commands/app_test.rb @@ -55,13 +55,13 @@ class CommandsAppTest < ActiveSupport::TestCase test "stop" do assert_equal \ - "docker ps --quiet --filter label=service=app --filter label=role=web | xargs docker stop", + "docker ps --quiet --filter label=service=app --filter label=role=web | xargs docker stop -t 10", 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", + "docker container ls --all --filter name=app-web-123 --quiet | xargs docker stop -t 10", new_command.stop(version: "123").join(" ") end