Initial windows runtime work
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
@@ -2,14 +2,10 @@ package main
|
||||
|
||||
// register containerd builtins here
|
||||
import (
|
||||
_ "github.com/containerd/containerd/linux"
|
||||
_ "github.com/containerd/containerd/metrics/cgroups"
|
||||
_ "github.com/containerd/containerd/services/content"
|
||||
_ "github.com/containerd/containerd/services/execution"
|
||||
_ "github.com/containerd/containerd/services/healthcheck"
|
||||
_ "github.com/containerd/containerd/services/images"
|
||||
_ "github.com/containerd/containerd/services/metrics"
|
||||
_ "github.com/containerd/containerd/services/rootfs"
|
||||
_ "github.com/containerd/containerd/snapshot/btrfs"
|
||||
_ "github.com/containerd/containerd/snapshot/overlay"
|
||||
)
|
||||
|
||||
8
cmd/containerd/builtins_linux.go
Normal file
8
cmd/containerd/builtins_linux.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/containerd/containerd/linux"
|
||||
_ "github.com/containerd/containerd/metrics/cgroups"
|
||||
_ "github.com/containerd/containerd/snapshot/btrfs"
|
||||
_ "github.com/containerd/containerd/snapshot/overlay"
|
||||
)
|
||||
6
cmd/containerd/builtins_windows.go
Normal file
6
cmd/containerd/builtins_windows.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "github.com/containerd/containerd/snapshot/windows"
|
||||
_ "github.com/containerd/containerd/windows"
|
||||
)
|
||||
@@ -7,21 +7,6 @@ import (
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
func defaultConfig() *config {
|
||||
return &config{
|
||||
Root: "/var/lib/containerd",
|
||||
State: "/run/containerd",
|
||||
GRPC: grpcConfig{
|
||||
Socket: "/run/containerd/containerd.sock",
|
||||
},
|
||||
Debug: debug{
|
||||
Level: "info",
|
||||
Socket: "/run/containerd/debug.sock",
|
||||
},
|
||||
Snapshotter: "overlay",
|
||||
}
|
||||
}
|
||||
|
||||
// loadConfig loads the config from the provided path
|
||||
func loadConfig(path string) error {
|
||||
md, err := toml.DecodeFile(path, conf)
|
||||
@@ -73,14 +58,14 @@ func (c *config) WriteTo(w io.Writer) (int64, error) {
|
||||
}
|
||||
|
||||
type grpcConfig struct {
|
||||
Socket string `toml:"socket"`
|
||||
Uid int `toml:"uid"`
|
||||
Gid int `toml:"gid"`
|
||||
Address string `toml:"address"`
|
||||
Uid int `toml:"uid"`
|
||||
Gid int `toml:"gid"`
|
||||
}
|
||||
|
||||
type debug struct {
|
||||
Socket string `toml:"socket"`
|
||||
Level string `toml:"level"`
|
||||
Address string `toml:"address"`
|
||||
Level string `toml:"level"`
|
||||
}
|
||||
|
||||
type metricsConfig struct {
|
||||
|
||||
18
cmd/containerd/config_unix.go
Normal file
18
cmd/containerd/config_unix.go
Normal file
@@ -0,0 +1,18 @@
|
||||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
func defaultConfig() *config {
|
||||
return &config{
|
||||
Root: "/var/lib/containerd",
|
||||
State: "/run/containerd",
|
||||
GRPC: grpcConfig{
|
||||
Address: "/run/containerd/containerd.sock",
|
||||
},
|
||||
Debug: debug{
|
||||
Level: "info",
|
||||
Address: "/run/containerd/debug.sock",
|
||||
},
|
||||
Snapshotter: "overlay",
|
||||
}
|
||||
}
|
||||
21
cmd/containerd/config_windows.go
Normal file
21
cmd/containerd/config_windows.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func defaultConfig() *config {
|
||||
return &config{
|
||||
Root: filepath.Join(os.Getenv("programfiles"), "containerd", "root"),
|
||||
State: filepath.Join(os.Getenv("programfiles"), "containerd", "state"),
|
||||
GRPC: grpcConfig{
|
||||
Address: `\\.\pipe\containerd-containerd`,
|
||||
},
|
||||
Debug: debug{
|
||||
Level: "info",
|
||||
Address: `\\.\pipe\containerd-debug`,
|
||||
},
|
||||
Snapshotter: "windows",
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
@@ -27,7 +26,6 @@ import (
|
||||
"github.com/containerd/containerd/images"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/reaper"
|
||||
"github.com/containerd/containerd/snapshot"
|
||||
"github.com/containerd/containerd/sys"
|
||||
metrics "github.com/docker/go-metrics"
|
||||
@@ -65,7 +63,7 @@ func main() {
|
||||
cli.StringFlag{
|
||||
Name: "config,c",
|
||||
Usage: "path to the configuration file (Use 'default' to output the default toml)",
|
||||
Value: "/etc/containerd/config.toml",
|
||||
Value: defaultConfigPath,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "log-level,l",
|
||||
@@ -76,8 +74,8 @@ func main() {
|
||||
Usage: "containerd state directory",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "socket,s",
|
||||
Usage: "socket path for containerd's GRPC server",
|
||||
Name: "address,a",
|
||||
Usage: "address for containerd's GRPC server",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "root",
|
||||
@@ -90,12 +88,9 @@ func main() {
|
||||
// start the signal handler as soon as we can to make sure that
|
||||
// we don't miss any signals during boot
|
||||
signals := make(chan os.Signal, 2048)
|
||||
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGCHLD)
|
||||
if conf.Subreaper {
|
||||
log.G(global).Info("setting subreaper...")
|
||||
if err := sys.SetSubreaper(1); err != nil {
|
||||
return err
|
||||
}
|
||||
signal.Notify(signals, handledSignals...)
|
||||
if err := platformInit(context); err != nil {
|
||||
return err
|
||||
}
|
||||
log.G(global).Info("starting containerd boot...")
|
||||
|
||||
@@ -204,8 +199,8 @@ func before(context *cli.Context) error {
|
||||
d: &conf.State,
|
||||
},
|
||||
{
|
||||
name: "socket",
|
||||
d: &conf.GRPC.Socket,
|
||||
name: "address",
|
||||
d: &conf.GRPC.Address,
|
||||
},
|
||||
} {
|
||||
if s := context.GlobalString(v.name); s != "" {
|
||||
@@ -249,11 +244,11 @@ func newMetricsHandler() http.Handler {
|
||||
}
|
||||
|
||||
func serveDebugAPI() error {
|
||||
path := conf.Debug.Socket
|
||||
path := conf.Debug.Address
|
||||
if path == "" {
|
||||
return errors.New("debug socket path cannot be empty")
|
||||
}
|
||||
l, err := sys.CreateUnixSocket(path)
|
||||
l, err := sys.GetLocalListener(path, conf.GRPC.Uid, conf.GRPC.Gid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -415,17 +410,14 @@ func loadServices(runtimes map[string]containerd.Runtime, store *content.Store,
|
||||
}
|
||||
|
||||
func serveGRPC(server *grpc.Server) error {
|
||||
path := conf.GRPC.Socket
|
||||
path := conf.GRPC.Address
|
||||
if path == "" {
|
||||
return errors.New("--socket path cannot be empty")
|
||||
}
|
||||
l, err := sys.CreateUnixSocket(path)
|
||||
l, err := sys.GetLocalListener(path, conf.GRPC.Uid, conf.GRPC.Gid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Chown(path, conf.GRPC.Uid, conf.GRPC.Gid); err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
defer l.Close()
|
||||
if err := server.Serve(l); err != nil {
|
||||
@@ -455,19 +447,3 @@ func interceptor(ctx gocontext.Context,
|
||||
}
|
||||
return grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler)
|
||||
}
|
||||
|
||||
func handleSignals(signals chan os.Signal, server *grpc.Server) error {
|
||||
for s := range signals {
|
||||
log.G(global).WithField("signal", s).Debug("received signal")
|
||||
switch s {
|
||||
case syscall.SIGCHLD:
|
||||
if err := reaper.Reap(); err != nil {
|
||||
log.G(global).WithError(err).Error("reap containerd processes")
|
||||
}
|
||||
default:
|
||||
server.Stop()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
48
cmd/containerd/main_unix.go
Normal file
48
cmd/containerd/main_unix.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// +build !windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/reaper"
|
||||
"github.com/containerd/containerd/sys"
|
||||
"github.com/urfave/cli"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultConfigPath = "/etc/containerd/config.toml"
|
||||
)
|
||||
|
||||
var (
|
||||
handledSignals = []os.Signal{syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGCHLD}
|
||||
)
|
||||
|
||||
func platformInit(context *cli.Context) error {
|
||||
if conf.Subreaper {
|
||||
log.G(global).Info("setting subreaper...")
|
||||
if err := sys.SetSubreaper(1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSignals(signals chan os.Signal, server *grpc.Server) error {
|
||||
for s := range signals {
|
||||
log.G(global).WithField("signal", s).Debug("received signal")
|
||||
switch s {
|
||||
case syscall.SIGCHLD:
|
||||
if err := reaper.Reap(); err != nil {
|
||||
log.G(global).WithError(err).Error("reap containerd processes")
|
||||
}
|
||||
default:
|
||||
server.Stop()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
28
cmd/containerd/main_windows.go
Normal file
28
cmd/containerd/main_windows.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/urfave/cli"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultConfigPath = filepath.Join(os.Getenv("programfiles"), "containerd", "config.toml")
|
||||
handledSignals = []os.Signal{syscall.SIGTERM, syscall.SIGINT}
|
||||
)
|
||||
|
||||
func platformInit(context *cli.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSignals(signals chan os.Signal, server *grpc.Server) error {
|
||||
for s := range signals {
|
||||
log.G(global).WithField("signal", s).Debug("received signal")
|
||||
server.Stop()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user