Make host connections close last
This commit is contained in:
parent
2ca5f193e4
commit
f7676e73ba
@ -328,7 +328,9 @@ func (config *BackyConfigFile) ExecuteCmds(opts *BackyConfigOpts) {
|
|||||||
|
|
||||||
func (c *BackyConfigFile) closeHostConnections() {
|
func (c *BackyConfigFile) closeHostConnections() {
|
||||||
for _, host := range c.Hosts {
|
for _, host := range c.Hosts {
|
||||||
|
if host.isProxyHost {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if host.SshClient != nil {
|
if host.SshClient != nil {
|
||||||
if _, err := host.SshClient.NewSession(); err == nil {
|
if _, err := host.SshClient.NewSession(); err == nil {
|
||||||
c.Logger.Info().Msgf("Closing host connection %s", host.HostName)
|
c.Logger.Info().Msgf("Closing host connection %s", host.HostName)
|
||||||
@ -336,6 +338,9 @@ func (c *BackyConfigFile) closeHostConnections() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, proxyHost := range host.ProxyHost {
|
for _, proxyHost := range host.ProxyHost {
|
||||||
|
if proxyHost.isProxyHost {
|
||||||
|
continue
|
||||||
|
}
|
||||||
if proxyHost.SshClient != nil {
|
if proxyHost.SshClient != nil {
|
||||||
if _, err := host.SshClient.NewSession(); err == nil {
|
if _, err := host.SshClient.NewSession(); err == nil {
|
||||||
c.Logger.Info().Msgf("Closing connection to proxy host %s", host.HostName)
|
c.Logger.Info().Msgf("Closing connection to proxy host %s", host.HostName)
|
||||||
@ -344,4 +349,12 @@ func (c *BackyConfigFile) closeHostConnections() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, host := range c.Hosts {
|
||||||
|
if host.SshClient != nil {
|
||||||
|
if _, err := host.SshClient.NewSession(); err == nil {
|
||||||
|
c.Logger.Info().Msgf("Closing proxy host connection %s", host.HostName)
|
||||||
|
host.SshClient.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -392,6 +392,7 @@ func (remoteConfig *Host) GetProxyJumpConfig(hosts map[string]*Host) error {
|
|||||||
remoteConfig.GetHostName()
|
remoteConfig.GetHostName()
|
||||||
remoteConfig.CombineHostNameWithPort()
|
remoteConfig.CombineHostNameWithPort()
|
||||||
remoteConfig.GetSshUserFromConfig()
|
remoteConfig.GetSshUserFromConfig()
|
||||||
|
remoteConfig.isProxyHost = true
|
||||||
if remoteConfig.HostName == "" {
|
if remoteConfig.HostName == "" {
|
||||||
return errors.Errorf("No hostname found or specified for host %s", remoteConfig.Host)
|
return errors.Errorf("No hostname found or specified for host %s", remoteConfig.Host)
|
||||||
}
|
}
|
||||||
|
@ -50,6 +50,7 @@ type (
|
|||||||
PrivateKeyPassword string `yaml:"privatekeypassword,omitempty"`
|
PrivateKeyPassword string `yaml:"privatekeypassword,omitempty"`
|
||||||
useDefaultConfig bool
|
useDefaultConfig bool
|
||||||
User string `yaml:"user,omitempty"`
|
User string `yaml:"user,omitempty"`
|
||||||
|
isProxyHost bool
|
||||||
// ProxyHost holds the configuration for a ProxyJump host
|
// ProxyHost holds the configuration for a ProxyJump host
|
||||||
ProxyHost []*Host
|
ProxyHost []*Host
|
||||||
// CertPath string `yaml:"cert_path,omitempty"`
|
// CertPath string `yaml:"cert_path,omitempty"`
|
||||||
|
Loading…
Reference in New Issue
Block a user