-
Notifications
You must be signed in to change notification settings - Fork 0
/
insgorund.go
55 lines (48 loc) · 1.2 KB
/
insgorund.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
49
50
51
52
53
54
55
package testutils
import (
"os"
"os/exec"
"syscall"
"time"
"github.com/pkg/errors"
)
// StartInsgorund starts `insgorund` process
func StartInsgorund(cmdPath, lProto, listen, upstreamProto, upstreamAddr string) (func(), error) {
var args []string
if listen != "" {
args = append(args, "-l", listen)
} else {
return nil, errors.New("listen is required to start `insgorund`")
}
if lProto != "" {
args = append(args, "--proto", lProto)
}
if upstreamAddr != "" {
args = append(args, "--rpc", upstreamAddr)
} else {
return nil, errors.New("address of the upstream is required to start `insgorund`")
}
if upstreamProto != "" {
args = append(args, "--rpc-proto", upstreamProto)
}
if cmdPath == "" {
return nil, errors.New("command's path is required to start `insgorund`")
}
runner := exec.Command(cmdPath, args...)
runner.Stdout = os.Stdout
runner.Stderr = os.Stderr
err := runner.Start()
if err != nil {
return nil, errors.Wrap(err, "couldn't start `insgorund`")
}
// XXX: dirty hack
time.Sleep(200 * time.Millisecond)
return func() {
err := runner.Process.Signal(syscall.SIGINT)
if err != nil {
return
}
// XXX: dirty hack
time.Sleep(200 * time.Millisecond)
}, nil
}