diff --git a/go.mod b/go.mod index 57383a1..5c338f9 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.22.5 require ( github.com/blacknon/go-sshproc v0.1.1 - github.com/blacknon/lssh v0.6.11 + github.com/blacknon/lssh v0.6.13 github.com/blacknon/mview v0.1.5 github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 github.com/dustin/go-humanize v1.0.0 @@ -24,7 +24,7 @@ require ( github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 // indirect github.com/blacknon/crypto11 v1.2.7 // indirect github.com/blacknon/go-nfs-sshlib v0.0.3 // indirect - github.com/blacknon/go-sshlib v0.1.17 // indirect + github.com/blacknon/go-sshlib v0.1.18 // indirect github.com/blacknon/go-x11auth v0.1.0 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/dchest/bcrypt_pbkdf v0.0.0-20150205184540-83f37f9c154a // indirect diff --git a/go.sum b/go.sum index 2090525..08c6351 100644 --- a/go.sum +++ b/go.sum @@ -15,14 +15,14 @@ github.com/blacknon/crypto11 v1.2.7 h1:LKrnCeXAk4jQmpJTeg/tVvNjqEgKHIE+tYSNXQj8F github.com/blacknon/crypto11 v1.2.7/go.mod h1:Z24sFD9pMX3NdUFzX52ggcV7HurAYAGvxud73BrHudA= github.com/blacknon/go-nfs-sshlib v0.0.3 h1:tq83kTZibrr99/GCn0pqkJhmBTDMupL/eMI3ZhSM0G4= github.com/blacknon/go-nfs-sshlib v0.0.3/go.mod h1:jaCmHgFoj8j08rGrBnhJ4nFO7nUWs4xFrUd2vEPwyx8= -github.com/blacknon/go-sshlib v0.1.17 h1:iEMIeYsAJLigapB61i4D3VpdOnFboWpztob0ufhmkhQ= -github.com/blacknon/go-sshlib v0.1.17/go.mod h1:DN5Vkl/FpEzVxGoS0p8uBsBoHpVywiHbALr9UxcfJxw= +github.com/blacknon/go-sshlib v0.1.18 h1:gzkplZuAH2aHARng2YbiEjzGufZomPdGoMQuqmdA2R0= +github.com/blacknon/go-sshlib v0.1.18/go.mod h1:DN5Vkl/FpEzVxGoS0p8uBsBoHpVywiHbALr9UxcfJxw= github.com/blacknon/go-sshproc v0.1.1 h1:Zhhm/lyC+lotbN8vqXD3fnxVbJP4ILMCu086PuTLXFo= github.com/blacknon/go-sshproc v0.1.1/go.mod h1:FoW0cVjAxqtJVrhgzif6SOBsZ27EiMF/i2iCqiUPwBY= github.com/blacknon/go-x11auth v0.1.0 h1:SnljCPWcvglWeGAlKc1RAPMHnOfMpM9+GrTGEUQ1lqQ= github.com/blacknon/go-x11auth v0.1.0/go.mod h1:SKOCa19LluXHyB+OaLYobquzceE0SWxVW7e/qU5xGBM= -github.com/blacknon/lssh v0.6.11 h1:6LF/X7Fhwyj7zG+RsxF4vpYd0MJIFIw4vgzcBv4waNk= -github.com/blacknon/lssh v0.6.11/go.mod h1:8+Ok3QU0WxDP91XQaCj/VJ8PnYkLwxelqLEFGid+RBg= +github.com/blacknon/lssh v0.6.13 h1:tbBPrQEWZCtOydrNM0AU66+kYP6A8CICC5IZByjUbq4= +github.com/blacknon/lssh v0.6.13/go.mod h1:vATi4lxN/t+8YgOQL8ZktxyJnmA7ZMcct8ZIloCuaxY= github.com/blacknon/mview v0.1.5 h1:Ojh13uB1MH6Rfg7uaK6BdbsNV05bWik6eFVaG2sD1M8= github.com/blacknon/mview v0.1.5/go.mod h1:zDpvfOFP8nr541iWsT/QEGSPh78DmkGEVeWYUM5gYSI= github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8 h1:SjZ2GvvOononHOpK84APFuMvxqsk3tEIaKH/z4Rpu3g= diff --git a/main.go b/main.go index 2436d9e..fdbae74 100644 --- a/main.go +++ b/main.go @@ -70,7 +70,7 @@ USAGE: app.Name = "LsMon" app.Usage = "TUI list select and parallel ssh client shell." app.Copyright = "blacknon(blacknon@orebibou.com)" - app.Version = "0.1.3" + app.Version = "0.1.5" // Set options app.Flags = []cli.Flag{ diff --git a/mon/node.go b/mon/node.go index 6645843..6e00284 100644 --- a/mon/node.go +++ b/mon/node.go @@ -192,23 +192,22 @@ func (n *Node) Connect(r *sshrun.Run) (err error) { } // Create Session and run KeepAlive - con.SetLog("/dev/null", false) - con.SendKeepAliveInterval = 1 + con.SendKeepAliveInterval = 10 procCon := &sshproc.ConnectWithProc{Connect: con} err = procCon.CreateSftpClient() if err != nil { - con.Client.Close() + log.Printf("CreateSftpClient %s Error: %s", n.ServerName, err) + n.con.Connect = nil return } n.con = procCon - session, err := con.CreateSession() if err != nil { - procCon.Client.Close() + log.Printf("CreateSession %s Error: %s", n.ServerName, err) + n.con.Connect = nil procCon.CloseSftpClient() - con.Client.Close() return } @@ -216,6 +215,13 @@ func (n *Node) Connect(r *sshrun.Run) (err error) { go func() { log.Println("Start KeepAlive. Server:", n.ServerName) con.SendKeepAlive(session) + + // close sftp client + session.Close() + err := procCon.CloseSftpClient() + if err != nil { + log.Printf("CloseSession Error: %s", err) + } }() return diff --git a/mon/panel_base.go b/mon/panel_base.go index 2f732b8..fb2c82f 100644 --- a/mon/panel_base.go +++ b/mon/panel_base.go @@ -75,18 +75,18 @@ func (m *Monitor) reconnectServer() { for range ticker.C { var wg sync.WaitGroup for _, node := range m.Nodes { - log.Printf("start Reconnect Server: %s", node.ServerName) - wg.Add(1) + // Check client alive + if !node.CheckClientAlive() { + wg.Add(1) - go func(n *Node, r *ssh.Run, wg *sync.WaitGroup) { - defer wg.Done() - if !n.CheckClientAlive() { + go func(n *Node, r *ssh.Run, wgg *sync.WaitGroup) { + defer wgg.Done() log.Printf("try Reconnect Server: %s", n.ServerName) err := n.Connect(r) - log.Printf("exit Reconnect Server: %s, err: %s", n.ServerName, err) - } - }(node, m.r, &wg) + log.Printf("exit Reconnect Server: %s, err: %s", n.ServerName, err) + }(node, m.r, &wg) + } } wg.Wait()