From 74fe2d7eab00622ec48a05c3f12fbdda5343f490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Sat, 23 Dec 2023 02:22:45 +0100 Subject: [PATCH] add stop timeout to config. --- internal/config/room.go | 7 +++++++ internal/room/manager.go | 15 ++++++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/config/room.go b/internal/config/room.go index c5d78a8..80b674b 100644 --- a/internal/config/room.go +++ b/internal/config/room.go @@ -32,6 +32,7 @@ type Room struct { PathPrefix string Labels []string WaitEnabled bool + StopTimeoutSec int StorageEnabled bool StorageInternal string @@ -100,6 +101,11 @@ func (Room) Init(cmd *cobra.Command) error { return err } + cmd.PersistentFlags().Int("stop_timeout", 10, "timeout in seconds for stopping the room with SIGTERM, after that SIGKILL is used (0 to disable, -1 to wait forever)") + if err := viper.BindPFlag("stop_timeout", cmd.PersistentFlags().Lookup("stop_timeout")); err != nil { + return err + } + // Data cmd.PersistentFlags().Bool("storage.enabled", true, "whether storage is enabled, where peristent containers data will be stored") @@ -207,6 +213,7 @@ func (s *Room) Set() { s.PathPrefix = path.Join("/", path.Clean(viper.GetString("path_prefix"))) s.Labels = viper.GetStringSlice("labels") s.WaitEnabled = viper.GetBool("wait_enabled") + s.StopTimeoutSec = viper.GetInt("stop_timeout") s.StorageEnabled = viper.GetBool("storage.enabled") s.StorageInternal = viper.GetString("storage.internal") diff --git a/internal/room/manager.go b/internal/room/manager.go index 9be2445..03d98f2 100644 --- a/internal/room/manager.go +++ b/internal/room/manager.go @@ -724,7 +724,10 @@ func (manager *RoomManagerCtx) Remove(ctx context.Context, id string) error { } // Stop the actual container - err = manager.client.ContainerStop(ctx, id, container.StopOptions{}) + err = manager.client.ContainerStop(ctx, id, container.StopOptions{ + Signal: "SIGTERM", + Timeout: &manager.config.StopTimeoutSec, + }) if err != nil { return err @@ -998,7 +1001,10 @@ func (manager *RoomManagerCtx) Stop(ctx context.Context, id string) error { } // Stop the actual container - return manager.client.ContainerStop(ctx, id, container.StopOptions{}) + return manager.client.ContainerStop(ctx, id, container.StopOptions{ + Signal: "SIGTERM", + Timeout: &manager.config.StopTimeoutSec, + }) } func (manager *RoomManagerCtx) Restart(ctx context.Context, id string) error { @@ -1008,7 +1014,10 @@ func (manager *RoomManagerCtx) Restart(ctx context.Context, id string) error { } // Restart the actual container - return manager.client.ContainerRestart(ctx, id, container.StopOptions{}) + return manager.client.ContainerRestart(ctx, id, container.StopOptions{ + Signal: "SIGTERM", + Timeout: &manager.config.StopTimeoutSec, + }) } // events