Add runtime output

This commit is contained in:
Asim Aslam
2019-09-24 19:00:11 +01:00
parent 1b08036a0b
commit 96e79c4498
5 changed files with 535 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ package runtime
import (
"errors"
"io"
"strings"
"sync"
"time"
@@ -31,6 +32,9 @@ type service struct {
closed chan bool
err error
// output for logs
output io.Writer
// service to manage
*Service
// process creator
@@ -81,9 +85,15 @@ func newService(s *Service, c CreateOptions) *service {
Env: c.Env,
Args: args,
},
output: c.Output,
}
}
func (s *service) streamOutput() {
go io.Copy(s.output, s.PID.Output)
go io.Copy(s.output, s.PID.Error)
}
func (s *service) Running() bool {
s.RLock()
defer s.RUnlock()
@@ -103,7 +113,7 @@ func (s *service) Start() error {
s.closed = make(chan bool)
// TODO: pull source & build binary
log.Debugf("Runtime service %s forking new process\n")
p, err := s.Process.Fork(s.Exec)
if err != nil {
return err
@@ -114,6 +124,10 @@ func (s *service) Start() error {
// set to running
s.running = true
if s.output != nil {
s.streamOutput()
}
// wait and watch
go s.Wait()