close interactive shell cmd on session restart
This commit is contained in:
parent
988ef7de8e
commit
227dc81036
|
@ -25,7 +25,7 @@ type PtyInteractiveShell struct {
|
|||
item *Item
|
||||
variables []string
|
||||
cmd *exec.Cmd
|
||||
File io.WriteCloser
|
||||
file io.WriteCloser
|
||||
ch chan string
|
||||
errCount int
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ func (s *PtyInteractiveShell) init() error {
|
|||
}()
|
||||
|
||||
s.cmd = cmd
|
||||
s.File = file
|
||||
s.file = file
|
||||
s.ch = channel
|
||||
|
||||
_, err = file.Read(make([]byte, 4096))
|
||||
|
@ -65,10 +65,12 @@ func (s *PtyInteractiveShell) init() error {
|
|||
|
||||
func (s *PtyInteractiveShell) execute() (string, error) {
|
||||
|
||||
_, err := io.WriteString(s.File, fmt.Sprintf(" %s\n", s.item.sampleScript))
|
||||
_, err := io.WriteString(s.file, fmt.Sprintf(" %s\n", s.item.sampleScript))
|
||||
if err != nil {
|
||||
s.errCount++
|
||||
if s.errCount > errorThreshold {
|
||||
_ = s.cmd.Wait()
|
||||
_ = s.file.Close()
|
||||
s.item.ptyShell = nil // restart session
|
||||
}
|
||||
return "", errors.New(fmt.Sprintf("Failed to execute command: %s", err))
|
||||
|
|
|
@ -24,6 +24,7 @@ func (s *BasicInteractiveShell) init() error {
|
|||
|
||||
cmd := exec.Command("sh", "-c", *s.item.initScript)
|
||||
enrichEnvVariables(cmd, s.variables)
|
||||
cmd.Wait()
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
if err != nil {
|
||||
|
@ -72,6 +73,7 @@ func (s *BasicInteractiveShell) execute() (string, error) {
|
|||
if err != nil {
|
||||
s.errCount++
|
||||
if s.errCount > errorThreshold {
|
||||
_ = s.cmd.Wait()
|
||||
s.item.basicShell = nil // restart session
|
||||
}
|
||||
return "", errors.New(fmt.Sprintf("Failed to execute command: %s", err))
|
||||
|
|
Loading…
Reference in New Issue