diff --git a/Makefile b/Makefile index 3baf594..e949444 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ BIN_NAME := deploy build: - go build -buildmode=pie -ldflags '-w -s' -o $(BIN_NAME) ./cmd/svc/main.go + CGO_ENABLED=0 go build -buildmode=pie -ldflags '-w -s' -o $(BIN_NAME) ./cmd/svc/main.go clean: rm $(BIN_NAME) diff --git a/pkg/server/server.go b/pkg/server/server.go index 4d69cf2..3e22cfc 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -52,18 +52,33 @@ func (s *HTTPServer) setHandler(check map[string]string, script string) gin.Hand if err != nil { nlog.Warnf("setup pipe out fail: %+v\n", err) } + errReader, err := cmd.StderrPipe() + if err != nil { + nlog.Warnf("setup pipe out fail: %+v\n", err) + } if err := cmd.Start(); err != nil { nlog.Warnf("start script fail: %+v\n", err) } - in := bufio.NewScanner(reader) - for in.Scan() { - nlog.Debugf(in.Text()) - } - if err := in.Err(); err != nil { - nlog.Warnf("script error: %+v\n", err) - } + go func() { + in := bufio.NewScanner(reader) + for in.Scan() { + nlog.Debugf(in.Text()) + } + if err := in.Err(); err != nil { + nlog.Warnf("script error: %+v\n", err) + } + }() + go func() { + in := bufio.NewScanner(errReader) + for in.Scan() { + nlog.Debugf(in.Text()) + } + if err := in.Err(); err != nil { + nlog.Warnf("script error: %+v\n", err) + } + }() }()