Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Feed the stdout and stderr of the Pilot subprocess into glog
Browse files Browse the repository at this point in the history
Fixes: #166
  • Loading branch information
wallrj committed Dec 1, 2017
1 parent 0c0786b commit 01af37b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 0 additions & 2 deletions pkg/pilot/elasticsearch/v5/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ func (p *Pilot) CmdFunc(pilot *v1alpha1.Pilot) (*exec.Cmd, error) {
}

cmd := exec.Command("elasticsearch")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Env = p.env().Strings()

return cmd, nil
Expand Down
28 changes: 28 additions & 0 deletions pkg/pilot/genericpilot/process/process.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package process

import (
"bufio"
"fmt"
"os"
"os/exec"
"sync"

"github.com/golang/glog"
)
Expand Down Expand Up @@ -33,12 +35,37 @@ type Interface interface {
type Adapter struct {
Signals Signals
Cmd *exec.Cmd
wg sync.WaitGroup
}

var _ Interface = &Adapter{}

func (p *Adapter) Start() error {
glog.V(2).Infof("Starting process: %v", p.Cmd.Args)
stdout, err := p.Cmd.StdoutPipe()
if err != nil {
return err
}
p.wg.Add(1)
go func() {
in := bufio.NewScanner(stdout)
for in.Scan() {
glog.Info(in.Text())
}
p.wg.Done()
}()
stderr, err := p.Cmd.StderrPipe()
if err != nil {
return err
}
p.wg.Add(1)
go func() {
in := bufio.NewScanner(stderr)
for in.Scan() {
glog.Error(in.Text())
}
p.wg.Done()
}()

if err := p.Cmd.Start(); err != nil {
return fmt.Errorf("error starting process: %s", err.Error())
Expand All @@ -47,6 +74,7 @@ func (p *Adapter) Start() error {
}

func (p *Adapter) Wait() error {
defer p.wg.Wait()
return p.Cmd.Wait()
}

Expand Down

0 comments on commit 01af37b

Please sign in to comment.