diff --git a/cmd/containerd/config_linux.go b/cmd/containerd/config_linux.go index 538c37bf9..68d3f1629 100644 --- a/cmd/containerd/config_linux.go +++ b/cmd/containerd/config_linux.go @@ -6,7 +6,8 @@ import ( func defaultConfig() *server.Config { return &server.Config{ - Root: "/var/lib/containerd", + Root: server.DefaultRootDir, + State: server.DefaultStateDir, GRPC: server.GRPCConfig{ Address: server.DefaultAddress, }, diff --git a/cmd/containerd/config_unsupported.go b/cmd/containerd/config_unsupported.go index 6a7478f44..8f52def85 100644 --- a/cmd/containerd/config_unsupported.go +++ b/cmd/containerd/config_unsupported.go @@ -6,7 +6,8 @@ import "github.com/containerd/containerd/server" func defaultConfig() *server.Config { return &server.Config{ - Root: "/var/lib/containerd", + Root: server.DefaultRootDir, + State: server.DefaultStateDir, GRPC: server.GRPCConfig{ Address: server.DefaultAddress, }, diff --git a/cmd/containerd/config_windows.go b/cmd/containerd/config_windows.go index 20194221f..c11145172 100644 --- a/cmd/containerd/config_windows.go +++ b/cmd/containerd/config_windows.go @@ -1,15 +1,11 @@ package main -import ( - "os" - "path/filepath" - - "github.com/containerd/containerd/server" -) +import "github.com/containerd/containerd/server" func defaultConfig() *server.Config { return &server.Config{ - Root: filepath.Join(os.Getenv("programfiles"), "containerd", "root"), + Root: server.DefaultRootDir, + State: server.DefaultStateDir, GRPC: server.GRPCConfig{ Address: server.DefaultAddress, }, diff --git a/linux/runtime.go b/linux/runtime.go index 049c4328d..712175210 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -69,7 +69,7 @@ type Config struct { } func New(ic *plugin.InitContext) (interface{}, error) { - if err := os.MkdirAll(ic.Root, 0711); err != nil { + if err := os.MkdirAll(ic.State, 0711); err != nil { return nil, err } monitor, err := ic.Get(plugin.TaskMonitorPlugin) @@ -82,7 +82,7 @@ func New(ic *plugin.InitContext) (interface{}, error) { } cfg := ic.Config.(*Config) r := &Runtime{ - root: ic.Root, + root: ic.State, remote: !cfg.NoShim, shim: cfg.Shim, shimDebug: cfg.ShimDebug, diff --git a/plugin/context.go b/plugin/context.go index 16cf1b8b7..dc5fb1528 100644 --- a/plugin/context.go +++ b/plugin/context.go @@ -9,16 +9,18 @@ import ( "github.com/containerd/containerd/log" ) -func NewContext(ctx context.Context, plugins map[PluginType]map[string]interface{}, root, id string) *InitContext { +func NewContext(ctx context.Context, plugins map[PluginType]map[string]interface{}, root, state, id string) *InitContext { return &InitContext{ plugins: plugins, Root: filepath.Join(root, id), + State: filepath.Join(state, id), Context: log.WithModule(ctx, id), } } type InitContext struct { Root string + State string Address string Context context.Context Config interface{} diff --git a/server/config.go b/server/config.go index 02659b669..dec0cfc57 100644 --- a/server/config.go +++ b/server/config.go @@ -11,6 +11,8 @@ import ( type Config struct { // Root is the path to a directory where containerd will store persistent data Root string `toml:"root"` + // State is the path to a directory where containerd will store transient data + State string `toml:"state"` // GRPC configuration settings GRPC GRPCConfig `toml:"grpc"` // Debug and profiling settings diff --git a/server/server.go b/server/server.go index 940f40eaf..40b140159 100644 --- a/server/server.go +++ b/server/server.go @@ -36,9 +36,15 @@ func New(ctx context.Context, config *Config) (*Server, error) { if config.Root == "" { return nil, errors.New("root must be specified") } + if config.State == "" { + return nil, errors.New("state must be specified") + } if err := os.MkdirAll(config.Root, 0711); err != nil { return nil, err } + if err := os.MkdirAll(config.State, 0711); err != nil { + return nil, err + } if err := apply(ctx, config); err != nil { return nil, err } @@ -66,6 +72,7 @@ func New(ctx context.Context, config *Config) (*Server, error) { ctx, initialized, config.Root, + config.State, id, ) initContext.Events = s.events diff --git a/server/server_linux.go b/server/server_linux.go index 58001cca0..34d35d012 100644 --- a/server/server_linux.go +++ b/server/server_linux.go @@ -9,6 +9,12 @@ import ( ) const ( + // DefaultRootDir is the default location used by containerd to store + // persistent data + DefaultRootDir = "/var/lib/containerd" + // DefaultStateDir is the default location used by containerd to store + // transient data + DefaultStateDir = "/run/containerd" // DefaultAddress is the default unix socket address DefaultAddress = "/run/containerd/containerd.sock" // DefaultDebuggAddress is the default unix socket address for pprof data diff --git a/server/server_unsupported.go b/server/server_unsupported.go index 197bfa029..0ec5d7e0a 100644 --- a/server/server_unsupported.go +++ b/server/server_unsupported.go @@ -5,6 +5,12 @@ package server import "context" const ( + // DefaultRootDir is the default location used by containerd to store + // persistent data + DefaultRootDir = "/var/lib/containerd" + // DefaultStateDir is the default location used by containerd to store + // transient data + DefaultStateDir = "/run/containerd" // DefaultAddress is the default unix socket address DefaultAddress = "/run/containerd/containerd.sock" // DefaultDebuggAddress is the default unix socket address for pprof data diff --git a/server/server_windows.go b/server/server_windows.go index 0fb9f64be..b35e776f7 100644 --- a/server/server_windows.go +++ b/server/server_windows.go @@ -2,7 +2,20 @@ package server -import "context" +import ( + "context" + "os" + "path/filepath" +) + +var ( + // DefaultRootDir is the default location used by containerd to store + // persistent data + DefaultRootDir = filepath.Join(os.Getenv("programfiles"), "containerd", "root") + // DefaultStateDir is the default location used by containerd to store + // transient data + DefaultStateDir = filepath.Join(os.Getenv("programfiles"), "containerd", "state") +) const ( // DefaultAddress is the default winpipe address