diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2021-07-09 14:41:41 +0300 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2021-07-15 14:39:33 +0300 |
commit | 569a0197cacc75270776217c27e9d709907a9dfa (patch) | |
tree | b693a2244f3d715d48df83eac70bdf6630e51d3a /internal/config/config.go | |
parent | d3711d8d7e781dbff01d8ae5c7a1d5b800c5c8a2 (diff) | |
download | gitlab-shell-569a0197cacc75270776217c27e9d709907a9dfa.tar.gz |
Shutdown sshd gracefully
When interruption signal is sent, we are closing ssh listener to
prevent it from accepting new connections
Then after configured grace period, we cancel the context to
cancel all ongoing operations
Diffstat (limited to 'internal/config/config.go')
-rw-r--r-- | internal/config/config.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 23044cd..c58ea7d 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -8,6 +8,7 @@ import ( "path" "path/filepath" "sync" + "time" "gitlab.com/gitlab-org/labkit/tracing" yaml "gopkg.in/yaml.v2" @@ -25,6 +26,7 @@ type ServerConfig struct { ProxyProtocol bool `yaml:"proxy_protocol,omitempty"` WebListen string `yaml:"web_listen,omitempty"` ConcurrentSessionsLimit int64 `yaml:"concurrent_sessions_limit,omitempty"` + GracePeriodSeconds uint64 `yaml:"grace_period"` HostKeyFiles []string `yaml:"host_key_files,omitempty"` } @@ -69,6 +71,7 @@ var ( Listen: "[::]:22", WebListen: "localhost:9122", ConcurrentSessionsLimit: 10, + GracePeriodSeconds: 10, HostKeyFiles: []string{ "/run/secrets/ssh-hostkeys/ssh_host_rsa_key", "/run/secrets/ssh-hostkeys/ssh_host_ecdsa_key", @@ -77,6 +80,10 @@ var ( } ) +func (sc *ServerConfig) GracePeriod() time.Duration { + return time.Duration(sc.GracePeriodSeconds) * time.Second +} + func (c *Config) ApplyGlobalState() { if c.SslCertDir != "" { os.Setenv("SSL_CERT_DIR", c.SslCertDir) |