Prevent SSH connection restarts

Set a high idle timeout on the sshkit connection pool. This will
reduce the incidence of re-connection storms when a deployment has been
idle for a while (e.g. when waiting for a docker build).

The default timeout was 30 seconds, so we'll enable keepalives at a
30s interval to match. This is to help prevent connections from being
killed during long idle periods.
This commit is contained in:
Donal McBreen
2023-06-22 16:09:25 +01:00
parent b25cfa178b
commit f64b596907
4 changed files with 35 additions and 4 deletions

View File

@@ -143,6 +143,7 @@ class Mrsk::Commander
private
# Lazy setup of SSHKit
def configure_sshkit_with(config)
SSHKit::Backend::Netssh.pool.idle_timeout = config.sshkit_pool_idle_timeout
SSHKit::Backend::Netssh.configure do |sshkit|
sshkit.max_concurrent_starts = config.sshkit_max_concurrent_starts if config.sshkit_max_concurrent_starts
sshkit.ssh_options = config.ssh_options

View File

@@ -153,7 +153,7 @@ class Mrsk::Configuration
end
def ssh_options
{ user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ] }.compact
{ user: ssh_user, proxy: ssh_proxy, auth_methods: [ "publickey" ], keepalive: true, keepalive_interval: 30 }.compact
end
@@ -161,6 +161,15 @@ class Mrsk::Configuration
raw_config.sshkit["max_concurrent_starts"] if raw_config.sshkit.present?
end
def sshkit_pool_idle_timeout
if raw_config.sshkit.present?
raw_config.sshkit["pool_idle_timeout"] || 900
else
900
end
end
def healthcheck
{ "path" => "/up", "port" => 3000, "max_attempts" => 7 }.merge(raw_config.healthcheck || {})
end