-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprocess.go
47 lines (44 loc) · 1014 Bytes
/
process.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package sidecars
import (
"fmt"
log "github.com/sirupsen/logrus"
"os"
"os/exec"
"sync"
"syscall"
)
type process struct {
cmd *exec.Cmd
cmdHandler CmdHandler
name string
typeP string
noInterrupt bool
alwaysInterrupt bool
errChan chan error
signalChan chan os.Signal
wg *sync.WaitGroup
}
func (p *process) Start() {
entry := log.WithField(p.typeP, p.name)
entry.Infof("Starting %s %s ...", p.typeP, p.name)
defer p.wg.Done()
err := p.cmdHandler.Run()
if err != nil {
// if this come from a signal, we do not considered this as an error
select {
case <-p.signalChan:
return
default:
}
errMess := fmt.Sprintf("Error occurred on %s %s: %s", p.typeP, p.name, err.Error())
entry.Error(errMess)
if !p.noInterrupt {
p.errChan <- fmt.Errorf(errMess)
p.signalChan <- syscall.SIGINT
}
}
// if process stopped we should stop all other processes
if p.alwaysInterrupt {
p.signalChan <- syscall.SIGINT
}
}