ssh: Log and return stdout/stderr consistency
parent
b04b2ad5ee
commit
26dbaa8b28
|
@ -99,7 +99,7 @@ func teeSSH(s *ssh.Session, cmd string, outB io.Writer, errB io.Writer) error {
|
||||||
// RunCmd implements the Command Runner interface to run a exec.Cmd object
|
// RunCmd implements the Command Runner interface to run a exec.Cmd object
|
||||||
func (s *SSHRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error) {
|
func (s *SSHRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error) {
|
||||||
rr := &RunResult{Args: cmd.Args}
|
rr := &RunResult{Args: cmd.Args}
|
||||||
glog.Infof("(SSHRunner) Run: %v", rr.Command())
|
glog.Infof("Run: %v", rr.Command())
|
||||||
|
|
||||||
var outb, errb io.Writer
|
var outb, errb io.Writer
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
|
@ -131,20 +131,21 @@ func (s *SSHRunner) RunCmd(cmd *exec.Cmd) (*RunResult, error) {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
elapsed := time.Since(start)
|
|
||||||
err = teeSSH(sess, shellquote.Join(cmd.Args...), outb, errb)
|
err = teeSSH(sess, shellquote.Join(cmd.Args...), outb, errb)
|
||||||
if err == nil {
|
elapsed := time.Since(start)
|
||||||
// Reduce log spam
|
|
||||||
if elapsed > (1 * time.Second) {
|
|
||||||
glog.Infof("(SSHRunner) Done: %v: (%s)", rr.Command(), elapsed)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if exitError, ok := err.(*exec.ExitError); ok {
|
if exitError, ok := err.(*exec.ExitError); ok {
|
||||||
rr.ExitCode = exitError.ExitCode()
|
rr.ExitCode = exitError.ExitCode()
|
||||||
}
|
}
|
||||||
glog.Infof("(SSHRunner) Non-zero exit: %v: %v (%s)\n%s", rr.Command(), err, elapsed, rr.Output())
|
// Decrease log spam
|
||||||
|
if elapsed > (1 * time.Second) {
|
||||||
|
glog.Infof("Exit %d for %v: (%s)", rr.Command(), elapsed)
|
||||||
}
|
}
|
||||||
return rr, err
|
if err == nil {
|
||||||
|
return rr, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return rr, fmt.Errorf("%s: %v\nstdout: %s\nstderr: %s", rr.Command(), err, rr.Stdout.String(), rr.Stderr.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy copies a file to the remote over SSH.
|
// Copy copies a file to the remote over SSH.
|
||||||
|
|
Loading…
Reference in New Issue