forked from kata-containers/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kata_proxy.go
66 lines (53 loc) · 1.57 KB
/
kata_proxy.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
65
66
// Copyright (c) 2017 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"os/exec"
"syscall"
)
// This is the Kata Containers implementation of the proxy interface.
// This is pretty simple since it provides the same interface to both
// runtime and shim as if they were talking directly to the agent.
type kataProxy struct {
}
// The kata proxy doesn't need to watch the vm console, thus return false always.
func (p *kataProxy) consoleWatched() bool {
return false
}
// start is kataProxy start implementation for proxy interface.
func (p *kataProxy) start(params proxyParams) (int, string, error) {
if err := validateProxyParams(params); err != nil {
return -1, "", err
}
params.logger.Debug("Starting regular Kata proxy rather than built-in")
// construct the socket path the proxy instance will use
proxyURL, err := defaultProxyURL(params.id, SocketTypeUNIX)
if err != nil {
return -1, "", err
}
args := []string{
params.path,
"-listen-socket", proxyURL,
"-mux-socket", params.agentURL,
"-sandbox", params.id,
}
if params.debug {
args = append(args, "-log", "debug", "-agent-logs-socket", params.consoleURL)
}
cmd := exec.Command(args[0], args[1:]...)
cmd.SysProcAttr = &syscall.SysProcAttr{
Setsid: true,
}
if err := cmd.Start(); err != nil {
return -1, "", err
}
go cmd.Wait()
return cmd.Process.Pid, proxyURL, nil
}
// stop is kataProxy stop implementation for proxy interface.
func (p *kataProxy) stop(pid int) error {
// Signal the proxy with SIGTERM.
return syscall.Kill(pid, syscall.SIGTERM)
}