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 13, 2017
1 parent 8552009 commit cc83e38
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions hack/e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ function test_elasticsearchcluster() {
then
fail_test "Elasticsearch pilot did not update the document count"
fi
kubectl cluster-info dump --namespaces "${USER_NAMESPACE}" || true
if ! kubectl delete \
--namespace "${USER_NAMESPACE}" \
ElasticSearchClusters \
Expand Down
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
48 changes: 47 additions & 1 deletion 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,20 +35,64 @@ type Interface interface {
type Adapter struct {
Signals Signals
Cmd *exec.Cmd
wg sync.WaitGroup
}

var _ Interface = &Adapter{}

func (p *Adapter) startCommandOutputLoggers() error {
stdout, err := p.Cmd.StdoutPipe()
if err != nil {
return err
}
p.wg.Add(1)
go func() {
defer p.wg.Done()
in := bufio.NewScanner(stdout)
for in.Scan() {
glog.Infoln(in.Text())
}
err := in.Err()
if err != nil {
glog.Error(err)
}
}()

stderr, err := p.Cmd.StderrPipe()
if err != nil {
return err
}
p.wg.Add(1)
go func() {
defer p.wg.Done()
in := bufio.NewScanner(stderr)
for in.Scan() {
glog.Infoln(in.Text())
}
err := in.Err()
if err != nil {
glog.Error(err)
}
}()
return nil
}

func (p *Adapter) Start() error {
glog.V(2).Infof("Starting process: %v", p.Cmd.Args)

if err := p.Cmd.Start(); err != nil {
err := p.startCommandOutputLoggers()
if err != nil {
return err
}

if err = p.Cmd.Start(); err != nil {
return fmt.Errorf("error starting process: %s", err.Error())
}
return nil
}

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

Expand Down

0 comments on commit cc83e38

Please sign in to comment.