/
runmethod.go
64 lines (50 loc) · 1.41 KB
/
runmethod.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
56
57
58
59
60
61
62
63
64
package genericworker
import (
"log"
"os"
"os/exec"
"github.com/taskcluster/taskcluster/v64/tools/worker-runner/run"
"github.com/taskcluster/taskcluster/v64/tools/worker-runner/util"
"github.com/taskcluster/taskcluster/v64/tools/workerproto"
)
// runMethod allows supporting both run-as-a-service and run-as-an-executable modes.
type runMethod interface {
start(w *genericworker, state *run.State) (workerproto.Transport, error)
wait() error
}
// run with a command
func newCmdRunMethod() (runMethod, error) {
return &cmdRunMethod{}, nil
}
type cmdRunMethod struct {
cmd *exec.Cmd
}
func (m *cmdRunMethod) start(w *genericworker, state *run.State) (workerproto.Transport, error) {
// path to generic-worker binary
cmd := exec.Command(w.wicfg.Path)
cmd.Env = os.Environ()
cmd.Stderr = os.Stderr
cmdStdout, err := cmd.StdoutPipe()
if err != nil {
return nil, err
}
cmdStdin, err := cmd.StdinPipe()
if err != nil {
return nil, err
}
transp := workerproto.NewPipeTransport(cmdStdout, cmdStdin)
// pass config to generic-worker
cmd.Args = append(cmd.Args, "run", "--config", w.wicfg.ConfigPath, "--with-worker-runner")
m.cmd = cmd
err = cmd.Start()
if err != nil {
return nil, err
}
if err = util.DisableOOM(cmd.Process.Pid); err != nil {
log.Printf("Error disabling OOM killer for generic-worker: %v", err)
}
return transp, nil
}
func (m *cmdRunMethod) wait() error {
return m.cmd.Wait()
}