make conmon inherit env from ocid

Signed-off-by: HaoZhang <crazykev@zju.edu.cn>
This commit is contained in:
HaoZhang 2016-10-17 15:44:27 +08:00
parent af55785b53
commit 9c11cc7dba
4 changed files with 16 additions and 3 deletions

View file

@ -49,6 +49,11 @@ runtime = "{{ .Runtime }}"
# conmon is the path to conmon binary, used for managing the runtime. # conmon is the path to conmon binary, used for managing the runtime.
conmon = "{{ .Conmon }}" conmon = "{{ .Conmon }}"
# conmon_env is the environment variable list for conmon process,
# used for passing necessary environment variable to conmon or runtime.
conmon_env = [
{{ range $env := .ConmonEnv }}{{ printf "\t%q,\n" $env }}{{ end }}]
# selinux indicates whether or not SELinux will be used for pod # selinux indicates whether or not SELinux will be used for pod
# separation on the host. If you enable this flag, SELinux must be running # separation on the host. If you enable this flag, SELinux must be running
# on the host. # on the host.
@ -77,6 +82,9 @@ func DefaultConfig() *server.Config {
RuntimeConfig: server.RuntimeConfig{ RuntimeConfig: server.RuntimeConfig{
Runtime: "/usr/bin/runc", Runtime: "/usr/bin/runc",
Conmon: conmonPath, Conmon: conmonPath,
ConmonEnv: []string{
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
},
SELinux: selinux.SelinuxEnabled(), SELinux: selinux.SelinuxEnabled(),
}, },
ImageConfig: server.ImageConfig{ ImageConfig: server.ImageConfig{

View file

@ -31,12 +31,13 @@ const (
) )
// New creates a new Runtime with options provided // New creates a new Runtime with options provided
func New(runtimePath string, containerDir string, conmonPath string) (*Runtime, error) { func New(runtimePath string, containerDir string, conmonPath string, conmonEnv []string) (*Runtime, error) {
r := &Runtime{ r := &Runtime{
name: filepath.Base(runtimePath), name: filepath.Base(runtimePath),
path: runtimePath, path: runtimePath,
containerDir: containerDir, containerDir: containerDir,
conmonPath: conmonPath, conmonPath: conmonPath,
conmonEnv: conmonEnv,
} }
return r, nil return r, nil
} }
@ -47,6 +48,7 @@ type Runtime struct {
path string path string
containerDir string containerDir string
conmonPath string conmonPath string
conmonEnv []string
} }
// syncInfo is used to return data from monitor process to daemon // syncInfo is used to return data from monitor process to daemon
@ -113,7 +115,7 @@ func (r *Runtime) CreateContainer(c *Container) error {
cmd.Stderr = os.Stderr cmd.Stderr = os.Stderr
cmd.ExtraFiles = append(cmd.ExtraFiles, childPipe) cmd.ExtraFiles = append(cmd.ExtraFiles, childPipe)
// 0, 1 and 2 are stdin, stdout and stderr // 0, 1 and 2 are stdin, stdout and stderr
cmd.Env = append(cmd.Env, fmt.Sprintf("_OCI_SYNCPIPE=%d", 3)) cmd.Env = append(r.conmonEnv, fmt.Sprintf("_OCI_SYNCPIPE=%d", 3))
err = cmd.Start() err = cmd.Start()
if err != nil { if err != nil {

View file

@ -53,6 +53,9 @@ type RuntimeConfig struct {
// Conmon is the path to conmon binary, used for managing the runtime. // Conmon is the path to conmon binary, used for managing the runtime.
Conmon string `toml:"conmon"` Conmon string `toml:"conmon"`
// ConmonEnv is the environment variable list for conmon process.
ConmonEnv []string `toml:"conmon_env"`
// SELinux determines whether or not SELinux is used for pod separation. // SELinux determines whether or not SELinux is used for pod separation.
SELinux bool `toml:"selinux"` SELinux bool `toml:"selinux"`
} }

View file

@ -222,7 +222,7 @@ func New(config *Config) (*Server, error) {
return nil, err return nil, err
} }
r, err := oci.New(config.Runtime, config.ContainerDir, config.Conmon) r, err := oci.New(config.Runtime, config.ContainerDir, config.Conmon, config.ConmonEnv)
if err != nil { if err != nil {
return nil, err return nil, err
} }