forked from k8sgateway/k8sgateway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
48 lines (41 loc) · 853 Bytes
/
runner.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
48
package services
import (
"fmt"
"os"
"os/exec"
"strings"
"time"
ps "github.com/keybase/go-ps"
)
type Runner struct {
Sourcepath string
ComponentName string
}
func (r *Runner) waitForExternalProcess() error {
for {
procs, err := ps.Processes()
if err != nil {
panic(err)
}
for _, proc := range procs {
str, err := proc.Path()
if err != nil {
continue
}
if strings.Contains(str, r.Sourcepath) {
return nil
}
}
time.Sleep(time.Second)
}
}
func (r *Runner) run(c *exec.Cmd) (*exec.Cmd, error) {
if os.Getenv("USE_DEBUGGER_"+r.ComponentName) == "1" {
fmt.Printf("Please run the following command in your debugger:\n"+
"%v %v \n"+
"CWD %v \n"+
"looking for processes started from %v", c.Path, c.Args, c.Dir, r.Sourcepath)
return nil, r.waitForExternalProcess()
}
return c, c.Start()
}