From 9c11cc7dba555fe89b05bad73722550ece0de419 Mon Sep 17 00:00:00 2001 From: HaoZhang Date: Mon, 17 Oct 2016 15:44:27 +0800 Subject: [PATCH] make conmon inherit env from ocid Signed-off-by: HaoZhang --- cmd/server/config.go | 8 ++++++++ oci/oci.go | 6 ++++-- server/config.go | 3 +++ server/server.go | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/cmd/server/config.go b/cmd/server/config.go index c2ea7832..240a6a8a 100644 --- a/cmd/server/config.go +++ b/cmd/server/config.go @@ -49,6 +49,11 @@ runtime = "{{ .Runtime }}" # conmon is the path to conmon binary, used for managing the runtime. 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 # separation on the host. If you enable this flag, SELinux must be running # on the host. @@ -77,6 +82,9 @@ func DefaultConfig() *server.Config { RuntimeConfig: server.RuntimeConfig{ Runtime: "/usr/bin/runc", Conmon: conmonPath, + ConmonEnv: []string{ + "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + }, SELinux: selinux.SelinuxEnabled(), }, ImageConfig: server.ImageConfig{ diff --git a/oci/oci.go b/oci/oci.go index fea02b85..fb4db197 100644 --- a/oci/oci.go +++ b/oci/oci.go @@ -31,12 +31,13 @@ const ( ) // 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{ name: filepath.Base(runtimePath), path: runtimePath, containerDir: containerDir, conmonPath: conmonPath, + conmonEnv: conmonEnv, } return r, nil } @@ -47,6 +48,7 @@ type Runtime struct { path string containerDir string conmonPath string + conmonEnv []string } // 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.ExtraFiles = append(cmd.ExtraFiles, childPipe) // 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() if err != nil { diff --git a/server/config.go b/server/config.go index dad434c0..660d45b4 100644 --- a/server/config.go +++ b/server/config.go @@ -53,6 +53,9 @@ type RuntimeConfig struct { // Conmon is the path to conmon binary, used for managing the runtime. 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 bool `toml:"selinux"` } diff --git a/server/server.go b/server/server.go index ac558256..9e8e95f6 100644 --- a/server/server.go +++ b/server/server.go @@ -222,7 +222,7 @@ func New(config *Config) (*Server, error) { 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 { return nil, err }