diff options
author | Valery Piashchynski <[email protected]> | 2021-04-19 16:42:28 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-04-19 16:42:28 +0300 |
commit | baa12b092578d41218585d918fb7e1425700272d (patch) | |
tree | 91881bd0ac32c609ea01fafe3bbc15a13a67c392 /plugins/service/process.go | |
parent | 112b7b60bbc045f4935e1766be9d2266abf68b31 (diff) |
- Add tests, update Informer implementation
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'plugins/service/process.go')
-rw-r--r-- | plugins/service/process.go | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/plugins/service/process.go b/plugins/service/process.go index 06d0b4c2..49219eb0 100644 --- a/plugins/service/process.go +++ b/plugins/service/process.go @@ -20,15 +20,16 @@ type Process struct { command *exec.Cmd // rawCmd from the plugin rawCmd string + Pid int // root plugin error chan errCh chan error // logger log logger.Logger - ExecTimeout time.Duration - RestartAfterExit bool - RestartDelay time.Duration + ExecTimeout time.Duration + RemainAfterExit bool + RestartSec uint64 // process start time startTime time.Time @@ -36,14 +37,14 @@ type Process struct { } // NewServiceProcess constructs service process structure -func NewServiceProcess(restartAfterExit bool, execTimeout, restartDelay time.Duration, command string, l logger.Logger, errCh chan error) *Process { +func NewServiceProcess(restartAfterExit bool, execTimeout time.Duration, restartDelay uint64, command string, l logger.Logger, errCh chan error) *Process { return &Process{ - rawCmd: command, - RestartDelay: restartDelay, - ExecTimeout: execTimeout, - RestartAfterExit: restartAfterExit, - errCh: errCh, - log: l, + rawCmd: command, + RestartSec: restartDelay, + ExecTimeout: execTimeout, + RemainAfterExit: restartAfterExit, + errCh: errCh, + log: l, } } @@ -70,10 +71,11 @@ func (p *Process) start() { // start process waiting routine go p.wait() - // startExec + // execHandler checks for the execTimeout go p.execHandler() // save start time p.startTime = time.Now() + p.Pid = p.command.Process.Pid } // create command for the process @@ -93,12 +95,14 @@ func (p *Process) createProcess() { // wait process for exit func (p *Process) wait() { // Wait error doesn't matter here - _ = p.command.Wait() - + err := p.command.Wait() + if err != nil { + p.log.Error("process wait error", "error", err) + } // wait for restart delay - if p.RestartAfterExit { + if p.RemainAfterExit { // wait for the delay - time.Sleep(p.RestartDelay) + time.Sleep(time.Second * time.Duration(p.RestartSec)) // and start command again p.start() } |