2016-07-08 19:04:00 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-09-01 10:37:10 +00:00
|
|
|
"context"
|
2016-09-17 15:26:56 +00:00
|
|
|
"fmt"
|
2016-07-08 19:04:00 +00:00
|
|
|
"net"
|
2017-06-17 19:13:32 +00:00
|
|
|
"net/http"
|
|
|
|
_ "net/http/pprof"
|
2016-07-22 20:44:27 +00:00
|
|
|
"os"
|
2016-10-18 14:48:33 +00:00
|
|
|
"os/signal"
|
2016-10-13 14:57:48 +00:00
|
|
|
"sort"
|
2016-10-18 14:48:33 +00:00
|
|
|
"strings"
|
2016-07-08 19:04:00 +00:00
|
|
|
|
2016-11-22 19:25:48 +00:00
|
|
|
"github.com/containers/storage/pkg/reexec"
|
2017-07-25 19:16:43 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/libkpod"
|
2016-09-26 23:55:12 +00:00
|
|
|
"github.com/kubernetes-incubator/cri-o/server"
|
2017-03-22 17:58:35 +00:00
|
|
|
"github.com/opencontainers/selinux/go-selinux"
|
2017-08-05 11:40:46 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-09-01 10:37:10 +00:00
|
|
|
"github.com/soheilhy/cmux"
|
2016-07-20 01:30:05 +00:00
|
|
|
"github.com/urfave/cli"
|
2017-06-28 15:47:31 +00:00
|
|
|
"golang.org/x/sys/unix"
|
2016-07-08 19:04:00 +00:00
|
|
|
"google.golang.org/grpc"
|
2017-08-04 11:13:19 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubelet/apis/cri/v1alpha1/runtime"
|
2016-07-08 19:04:00 +00:00
|
|
|
)
|
|
|
|
|
2017-09-07 18:27:20 +00:00
|
|
|
// This is populated by the Makefile from the VERSION file
|
|
|
|
// in the repository
|
|
|
|
var version = ""
|
|
|
|
|
|
|
|
// gitCommit is the commit that the binary is being built from.
|
|
|
|
// It will be populated by the Makefile.
|
|
|
|
var gitCommit = ""
|
|
|
|
|
2017-06-30 18:55:40 +00:00
|
|
|
func validateConfig(config *server.Config) error {
|
|
|
|
switch config.ImageVolumes {
|
2017-07-25 19:16:43 +00:00
|
|
|
case libkpod.ImageVolumesMkdir:
|
|
|
|
case libkpod.ImageVolumesIgnore:
|
|
|
|
case libkpod.ImageVolumesBind:
|
2017-06-30 18:55:40 +00:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("Unrecognized image volume type specified")
|
|
|
|
|
|
|
|
}
|
2017-10-05 20:55:21 +00:00
|
|
|
|
|
|
|
// This needs to match the read buffer size in conmon
|
|
|
|
if config.LogSizeMax >= 0 && config.LogSizeMax < 8192 {
|
|
|
|
return fmt.Errorf("log size max should be negative or >= 8192")
|
|
|
|
}
|
2017-06-30 18:55:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:57:40 +00:00
|
|
|
func mergeConfig(config *server.Config, ctx *cli.Context) error {
|
2016-10-10 08:20:35 +00:00
|
|
|
// Don't parse the config if the user explicitly set it to "".
|
|
|
|
if path := ctx.GlobalString("config"); path != "" {
|
2017-07-27 17:18:07 +00:00
|
|
|
if err := config.UpdateFromFile(path); err != nil {
|
2016-10-10 08:20:35 +00:00
|
|
|
if ctx.GlobalIsSet("config") || !os.IsNotExist(err) {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't error out if --config wasn't explicitly set and the
|
|
|
|
// default doesn't exist. But we will log a warning about it, so
|
|
|
|
// the user doesn't miss it.
|
2017-08-28 18:05:03 +00:00
|
|
|
logrus.Warnf("default configuration file does not exist: %s", server.CrioConfigPath)
|
2016-10-10 08:20:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:57:40 +00:00
|
|
|
// Override options set with the CLI.
|
|
|
|
if ctx.GlobalIsSet("conmon") {
|
|
|
|
config.Conmon = ctx.GlobalString("conmon")
|
|
|
|
}
|
2016-10-18 14:48:33 +00:00
|
|
|
if ctx.GlobalIsSet("pause-command") {
|
|
|
|
config.PauseCommand = ctx.GlobalString("pause-command")
|
2016-10-13 13:25:31 +00:00
|
|
|
}
|
2016-10-18 14:48:33 +00:00
|
|
|
if ctx.GlobalIsSet("pause-image") {
|
|
|
|
config.PauseImage = ctx.GlobalString("pause-image")
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet("signature-policy") {
|
|
|
|
config.SignaturePolicyPath = ctx.GlobalString("signature-policy")
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet("root") {
|
|
|
|
config.Root = ctx.GlobalString("root")
|
|
|
|
}
|
2016-10-18 14:48:33 +00:00
|
|
|
if ctx.GlobalIsSet("runroot") {
|
|
|
|
config.RunRoot = ctx.GlobalString("runroot")
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet("storage-driver") {
|
|
|
|
config.Storage = ctx.GlobalString("storage-driver")
|
|
|
|
}
|
2017-02-24 22:05:07 +00:00
|
|
|
if ctx.GlobalIsSet("storage-opt") {
|
|
|
|
config.StorageOptions = ctx.GlobalStringSlice("storage-opt")
|
2016-10-18 14:48:33 +00:00
|
|
|
}
|
2017-07-20 18:43:41 +00:00
|
|
|
if ctx.GlobalIsSet("file-locking") {
|
|
|
|
config.FileLocking = ctx.GlobalBool("file-locking")
|
|
|
|
}
|
2017-06-08 13:45:34 +00:00
|
|
|
if ctx.GlobalIsSet("insecure-registry") {
|
2017-06-23 14:40:27 +00:00
|
|
|
config.InsecureRegistries = ctx.GlobalStringSlice("insecure-registry")
|
2017-06-08 13:45:34 +00:00
|
|
|
}
|
2017-07-20 08:01:23 +00:00
|
|
|
if ctx.GlobalIsSet("registry") {
|
|
|
|
config.Registries = ctx.GlobalStringSlice("registry")
|
|
|
|
}
|
2016-10-18 14:48:33 +00:00
|
|
|
if ctx.GlobalIsSet("default-transport") {
|
|
|
|
config.DefaultTransport = ctx.GlobalString("default-transport")
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet("listen") {
|
|
|
|
config.Listen = ctx.GlobalString("listen")
|
|
|
|
}
|
2017-06-12 22:31:16 +00:00
|
|
|
if ctx.GlobalIsSet("stream-address") {
|
|
|
|
config.StreamAddress = ctx.GlobalString("stream-address")
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet("stream-port") {
|
|
|
|
config.StreamPort = ctx.GlobalString("stream-port")
|
|
|
|
}
|
2016-10-10 09:57:40 +00:00
|
|
|
if ctx.GlobalIsSet("runtime") {
|
|
|
|
config.Runtime = ctx.GlobalString("runtime")
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet("selinux") {
|
|
|
|
config.SELinux = ctx.GlobalBool("selinux")
|
|
|
|
}
|
2016-11-23 09:41:48 +00:00
|
|
|
if ctx.GlobalIsSet("seccomp-profile") {
|
|
|
|
config.SeccompProfile = ctx.GlobalString("seccomp-profile")
|
|
|
|
}
|
2016-11-30 08:19:36 +00:00
|
|
|
if ctx.GlobalIsSet("apparmor-profile") {
|
|
|
|
config.ApparmorProfile = ctx.GlobalString("apparmor-profile")
|
|
|
|
}
|
2016-12-19 23:01:27 +00:00
|
|
|
if ctx.GlobalIsSet("cgroup-manager") {
|
|
|
|
config.CgroupManager = ctx.GlobalString("cgroup-manager")
|
|
|
|
}
|
2017-08-12 10:29:22 +00:00
|
|
|
if ctx.GlobalIsSet("hooks-dir-path") {
|
|
|
|
config.HooksDirPath = ctx.GlobalString("hooks-dir-path")
|
|
|
|
}
|
2017-07-07 21:43:35 +00:00
|
|
|
if ctx.GlobalIsSet("pids-limit") {
|
|
|
|
config.PidsLimit = ctx.GlobalInt64("pids-limit")
|
|
|
|
}
|
2017-09-25 22:37:10 +00:00
|
|
|
if ctx.GlobalIsSet("log-size-max") {
|
|
|
|
config.LogSizeMax = ctx.GlobalInt64("log-size-max")
|
|
|
|
}
|
2016-12-17 11:23:07 +00:00
|
|
|
if ctx.GlobalIsSet("cni-config-dir") {
|
|
|
|
config.NetworkDir = ctx.GlobalString("cni-config-dir")
|
|
|
|
}
|
|
|
|
if ctx.GlobalIsSet("cni-plugin-dir") {
|
|
|
|
config.PluginDir = ctx.GlobalString("cni-plugin-dir")
|
|
|
|
}
|
2017-06-30 18:55:40 +00:00
|
|
|
if ctx.GlobalIsSet("image-volumes") {
|
2017-07-25 19:16:43 +00:00
|
|
|
config.ImageVolumes = libkpod.ImageVolumesType(ctx.GlobalString("image-volumes"))
|
2017-06-30 18:55:40 +00:00
|
|
|
}
|
2016-10-10 09:57:40 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-09-01 10:37:10 +00:00
|
|
|
func catchShutdown(gserver *grpc.Server, sserver *server.Server, hserver *http.Server, signalled *bool) {
|
2016-10-18 14:48:33 +00:00
|
|
|
sig := make(chan os.Signal, 10)
|
2017-06-28 15:47:31 +00:00
|
|
|
signal.Notify(sig, unix.SIGINT, unix.SIGTERM)
|
2016-10-18 14:48:33 +00:00
|
|
|
go func() {
|
|
|
|
for s := range sig {
|
|
|
|
switch s {
|
2017-06-28 15:47:31 +00:00
|
|
|
case unix.SIGINT:
|
2016-10-18 14:48:33 +00:00
|
|
|
logrus.Debugf("Caught SIGINT")
|
2017-06-28 15:47:31 +00:00
|
|
|
case unix.SIGTERM:
|
2016-10-18 14:48:33 +00:00
|
|
|
logrus.Debugf("Caught SIGTERM")
|
|
|
|
default:
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
*signalled = true
|
|
|
|
gserver.GracefulStop()
|
2017-09-01 10:37:10 +00:00
|
|
|
hserver.Shutdown(context.Background())
|
2017-09-06 14:02:05 +00:00
|
|
|
// TODO(runcom): enable this after https://github.com/kubernetes/kubernetes/pull/51377
|
|
|
|
//sserver.StopStreamServer()
|
|
|
|
sserver.StopExitMonitor()
|
|
|
|
if err := sserver.Shutdown(); err != nil {
|
|
|
|
logrus.Warnf("error shutting down main service %v", err)
|
|
|
|
}
|
2016-10-18 14:48:33 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2016-07-08 19:04:00 +00:00
|
|
|
func main() {
|
2016-11-22 19:25:48 +00:00
|
|
|
if reexec.Init() {
|
|
|
|
return
|
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
app := cli.NewApp()
|
2017-09-07 18:27:20 +00:00
|
|
|
|
|
|
|
var v []string
|
|
|
|
if version != "" {
|
|
|
|
v = append(v, version)
|
|
|
|
}
|
|
|
|
if gitCommit != "" {
|
|
|
|
v = append(v, fmt.Sprintf("commit: %s", gitCommit))
|
|
|
|
}
|
2017-05-12 13:36:15 +00:00
|
|
|
app.Name = "crio"
|
|
|
|
app.Usage = "crio server"
|
2017-09-07 18:27:20 +00:00
|
|
|
app.Version = strings.Join(v, "\n")
|
2016-10-10 09:57:40 +00:00
|
|
|
app.Metadata = map[string]interface{}{
|
2017-01-17 00:20:35 +00:00
|
|
|
"config": server.DefaultConfig(),
|
2016-10-10 09:57:40 +00:00
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
|
|
|
|
app.Flags = []cli.Flag{
|
2016-10-10 08:20:35 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "config",
|
2017-08-28 18:05:03 +00:00
|
|
|
Value: server.CrioConfigPath,
|
2016-10-10 08:20:35 +00:00
|
|
|
Usage: "path to configuration file",
|
|
|
|
},
|
2016-09-28 19:49:46 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "conmon",
|
|
|
|
Usage: "path to the conmon executable",
|
|
|
|
},
|
2016-09-17 15:26:56 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
Usage: "enable debug output for logging",
|
|
|
|
},
|
2016-10-13 13:25:31 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "listen",
|
2017-05-12 13:36:15 +00:00
|
|
|
Usage: "path to crio socket",
|
2016-10-05 13:29:30 +00:00
|
|
|
},
|
2017-06-12 22:31:16 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "stream-address",
|
|
|
|
Usage: "bind address for streaming socket",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "stream-port",
|
|
|
|
Usage: "bind port for streaming socket (default: \"10010\")",
|
|
|
|
},
|
2016-09-17 15:26:56 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "log",
|
|
|
|
Value: "",
|
|
|
|
Usage: "set the log file path where internal debug information is written",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "log-format",
|
|
|
|
Value: "text",
|
|
|
|
Usage: "set the format used by logs ('text' (default), or 'json')",
|
|
|
|
},
|
2016-10-13 13:25:31 +00:00
|
|
|
cli.StringFlag{
|
2016-10-18 14:48:33 +00:00
|
|
|
Name: "pause-command",
|
|
|
|
Usage: "name of the pause command in the pause image",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "pause-image",
|
|
|
|
Usage: "name of the pause image",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "signature-policy",
|
|
|
|
Usage: "path to signature policy file",
|
2016-10-13 13:25:31 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "root",
|
2017-05-12 13:36:15 +00:00
|
|
|
Usage: "crio root dir",
|
2016-10-13 13:25:31 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2016-10-18 14:48:33 +00:00
|
|
|
Name: "runroot",
|
2017-05-12 13:36:15 +00:00
|
|
|
Usage: "crio state dir",
|
2016-10-18 14:48:33 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "storage-driver",
|
|
|
|
Usage: "storage driver",
|
|
|
|
},
|
|
|
|
cli.StringSliceFlag{
|
2017-02-24 22:05:07 +00:00
|
|
|
Name: "storage-opt",
|
2016-10-18 14:48:33 +00:00
|
|
|
Usage: "storage driver option",
|
|
|
|
},
|
2017-07-20 18:43:41 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "file-locking",
|
|
|
|
Usage: "enable or disable file-based locking",
|
|
|
|
},
|
2017-06-08 13:45:34 +00:00
|
|
|
cli.StringSliceFlag{
|
|
|
|
Name: "insecure-registry",
|
|
|
|
Usage: "whether to disable TLS verification for the given registry",
|
|
|
|
},
|
2017-07-20 08:01:23 +00:00
|
|
|
cli.StringSliceFlag{
|
|
|
|
Name: "registry",
|
|
|
|
Usage: "registry to be prepended when pulling unqualified images, can be specified multiple times",
|
|
|
|
},
|
2016-10-18 14:48:33 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "default-transport",
|
|
|
|
Usage: "default transport",
|
2016-10-13 13:25:31 +00:00
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2016-10-18 14:48:33 +00:00
|
|
|
Name: "runtime",
|
|
|
|
Usage: "OCI runtime path",
|
2016-10-13 13:25:31 +00:00
|
|
|
},
|
2016-11-23 09:41:48 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "seccomp-profile",
|
|
|
|
Usage: "default seccomp profile path",
|
|
|
|
},
|
2016-11-30 08:19:36 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "apparmor-profile",
|
2017-05-12 13:36:15 +00:00
|
|
|
Usage: "default apparmor profile name (default: \"crio-default\")",
|
2016-11-30 08:19:36 +00:00
|
|
|
},
|
2016-10-13 13:25:31 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "selinux",
|
|
|
|
Usage: "enable selinux support",
|
|
|
|
},
|
2016-12-19 23:01:27 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "cgroup-manager",
|
|
|
|
Usage: "cgroup manager (cgroupfs or systemd)",
|
|
|
|
},
|
2017-07-07 21:43:35 +00:00
|
|
|
cli.Int64Flag{
|
|
|
|
Name: "pids-limit",
|
2017-07-25 19:16:43 +00:00
|
|
|
Value: libkpod.DefaultPidsLimit,
|
2017-07-07 21:43:35 +00:00
|
|
|
Usage: "maximum number of processes allowed in a container",
|
|
|
|
},
|
2017-09-25 22:37:10 +00:00
|
|
|
cli.Int64Flag{
|
|
|
|
Name: "log-size-max",
|
|
|
|
Value: libkpod.DefaultLogSizeMax,
|
|
|
|
Usage: "maximum log size in bytes for a container",
|
|
|
|
},
|
2016-12-17 11:23:07 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "cni-config-dir",
|
|
|
|
Usage: "CNI configuration files directory",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "cni-plugin-dir",
|
|
|
|
Usage: "CNI plugin binaries directory",
|
|
|
|
},
|
2017-06-30 18:55:40 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "image-volumes",
|
2017-07-25 19:16:43 +00:00
|
|
|
Value: string(libkpod.ImageVolumesMkdir),
|
2017-09-11 22:43:53 +00:00
|
|
|
Usage: "image volume handling ('mkdir', 'bind', or 'ignore')",
|
2017-06-30 18:55:40 +00:00
|
|
|
},
|
2017-08-12 10:29:22 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "hooks-dir-path",
|
|
|
|
Usage: "set the OCI hooks directory path",
|
|
|
|
Value: libkpod.DefaultHooksDirPath,
|
|
|
|
Hidden: true,
|
|
|
|
},
|
2017-06-17 19:13:32 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "profile",
|
|
|
|
Usage: "enable pprof remote profiler on localhost:6060",
|
2017-04-25 05:51:37 +00:00
|
|
|
},
|
2017-07-26 17:57:55 +00:00
|
|
|
cli.IntFlag{
|
|
|
|
Name: "profile-port",
|
|
|
|
Value: 6060,
|
|
|
|
Usage: "port for the pprof profiler",
|
|
|
|
},
|
2017-08-03 00:38:50 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "enable-metrics",
|
|
|
|
Usage: "enable metrics endpoint for the servier on localhost:9090",
|
|
|
|
},
|
|
|
|
cli.IntFlag{
|
|
|
|
Name: "metrics-port",
|
|
|
|
Value: 9090,
|
|
|
|
Usage: "port for the metrics endpoint",
|
|
|
|
},
|
2016-09-17 15:26:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-05 06:59:10 +00:00
|
|
|
sort.Sort(cli.FlagsByName(app.Flags))
|
|
|
|
sort.Sort(cli.FlagsByName(configCommand.Flags))
|
2016-10-13 14:57:48 +00:00
|
|
|
|
2016-10-10 08:22:15 +00:00
|
|
|
app.Commands = []cli.Command{
|
|
|
|
configCommand,
|
|
|
|
}
|
|
|
|
|
2016-09-17 15:26:56 +00:00
|
|
|
app.Before = func(c *cli.Context) error {
|
2016-10-10 09:57:40 +00:00
|
|
|
// Load the configuration file.
|
|
|
|
config := c.App.Metadata["config"].(*server.Config)
|
|
|
|
if err := mergeConfig(config, c); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-06-30 18:55:40 +00:00
|
|
|
if err := validateConfig(config); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-10-26 19:45:29 +00:00
|
|
|
cf := &logrus.TextFormatter{
|
|
|
|
TimestampFormat: "2006-01-02 15:04:05.000000000Z07:00",
|
|
|
|
FullTimestamp: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.SetFormatter(cf)
|
|
|
|
|
2016-09-17 15:26:56 +00:00
|
|
|
if c.GlobalBool("debug") {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
2016-10-10 09:57:40 +00:00
|
|
|
|
2016-09-17 15:26:56 +00:00
|
|
|
if path := c.GlobalString("log"); path != "" {
|
|
|
|
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0666)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logrus.SetOutput(f)
|
|
|
|
}
|
2016-10-10 09:57:40 +00:00
|
|
|
|
2016-09-17 15:26:56 +00:00
|
|
|
switch c.GlobalString("log-format") {
|
|
|
|
case "text":
|
|
|
|
// retain logrus's default.
|
|
|
|
case "json":
|
|
|
|
logrus.SetFormatter(new(logrus.JSONFormatter))
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown log-format %q", c.GlobalString("log-format"))
|
|
|
|
}
|
2016-10-10 09:57:17 +00:00
|
|
|
|
2016-09-17 15:26:56 +00:00
|
|
|
return nil
|
2016-07-20 01:30:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
app.Action = func(c *cli.Context) error {
|
2017-06-17 19:13:32 +00:00
|
|
|
if c.GlobalBool("profile") {
|
2017-07-26 17:57:55 +00:00
|
|
|
profilePort := c.GlobalInt("profile-port")
|
|
|
|
profileEndpoint := fmt.Sprintf("localhost:%v", profilePort)
|
2017-06-17 19:13:32 +00:00
|
|
|
go func() {
|
2017-07-26 17:57:55 +00:00
|
|
|
http.ListenAndServe(profileEndpoint, nil)
|
2017-06-17 19:13:32 +00:00
|
|
|
}()
|
2017-04-25 05:51:37 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 09:57:40 +00:00
|
|
|
config := c.App.Metadata["config"].(*server.Config)
|
|
|
|
|
|
|
|
if !config.SELinux {
|
|
|
|
selinux.SetDisabled()
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := os.Stat(config.Runtime); os.IsNotExist(err) {
|
|
|
|
// path to runtime does not exist
|
|
|
|
return fmt.Errorf("invalid --runtime value %q", err)
|
|
|
|
}
|
|
|
|
|
2016-07-20 01:30:05 +00:00
|
|
|
// Remove the socket if it already exists
|
2016-10-10 09:57:40 +00:00
|
|
|
if _, err := os.Stat(config.Listen); err == nil {
|
|
|
|
if err := os.Remove(config.Listen); err != nil {
|
2016-09-19 07:21:14 +00:00
|
|
|
logrus.Fatal(err)
|
2016-07-20 01:30:05 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-10 09:57:40 +00:00
|
|
|
lis, err := net.Listen("unix", config.Listen)
|
2016-07-20 01:30:05 +00:00
|
|
|
if err != nil {
|
2016-09-19 07:21:14 +00:00
|
|
|
logrus.Fatalf("failed to listen: %v", err)
|
2016-07-20 01:30:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
s := grpc.NewServer()
|
|
|
|
|
2016-10-10 09:57:40 +00:00
|
|
|
service, err := server.New(config)
|
2016-07-20 01:30:05 +00:00
|
|
|
if err != nil {
|
2016-09-19 07:21:14 +00:00
|
|
|
logrus.Fatal(err)
|
2016-07-22 20:44:27 +00:00
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
|
2017-08-03 00:38:50 +00:00
|
|
|
if c.GlobalBool("enable-metrics") {
|
|
|
|
metricsPort := c.GlobalInt("metrics-port")
|
|
|
|
me, err := service.CreateMetricsEndpoint()
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("Failed to create metrics endpoint: %v", err)
|
|
|
|
}
|
|
|
|
l, err := net.Listen("tcp", fmt.Sprintf(":%v", metricsPort))
|
|
|
|
if err != nil {
|
|
|
|
logrus.Fatalf("Failed to create listener for metrics: %v", err)
|
|
|
|
}
|
|
|
|
go func() {
|
|
|
|
if err := http.Serve(l, me); err != nil {
|
|
|
|
logrus.Fatalf("Failed to serve metrics endpoint: %v", err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2016-07-20 01:30:05 +00:00
|
|
|
runtime.RegisterRuntimeServiceServer(s, service)
|
|
|
|
runtime.RegisterImageServiceServer(s, service)
|
2016-10-12 20:27:28 +00:00
|
|
|
|
|
|
|
// after the daemon is done setting up we can notify systemd api
|
|
|
|
notifySystem()
|
|
|
|
|
2017-08-13 01:35:55 +00:00
|
|
|
go func() {
|
|
|
|
service.StartExitMonitor()
|
|
|
|
}()
|
|
|
|
|
2017-09-01 10:37:10 +00:00
|
|
|
m := cmux.New(lis)
|
|
|
|
grpcL := m.Match(cmux.HTTP2HeaderField("content-type", "application/grpc"))
|
|
|
|
httpL := m.Match(cmux.HTTP1Fast())
|
|
|
|
|
|
|
|
infoMux := service.GetInfoMux()
|
|
|
|
srv := &http.Server{
|
|
|
|
Handler: infoMux,
|
|
|
|
}
|
2017-08-30 01:12:10 +00:00
|
|
|
|
2017-09-01 10:37:10 +00:00
|
|
|
graceful := false
|
|
|
|
catchShutdown(s, service, srv, &graceful)
|
|
|
|
|
|
|
|
go s.Serve(grpcL)
|
|
|
|
go srv.Serve(httpL)
|
|
|
|
|
2017-09-06 14:02:05 +00:00
|
|
|
serverCloseCh := make(chan struct{})
|
|
|
|
go func() {
|
|
|
|
defer close(serverCloseCh)
|
|
|
|
if err := m.Serve(); err != nil {
|
|
|
|
if graceful && strings.Contains(strings.ToLower(err.Error()), "use of closed network connection") {
|
|
|
|
err = nil
|
|
|
|
} else {
|
|
|
|
logrus.Errorf("Failed to serve grpc grpc request: %v", err)
|
|
|
|
}
|
2017-09-01 10:37:10 +00:00
|
|
|
}
|
2017-09-06 14:02:05 +00:00
|
|
|
}()
|
2016-10-18 14:48:33 +00:00
|
|
|
|
2017-09-06 14:02:05 +00:00
|
|
|
// TODO(runcom): enable this after https://github.com/kubernetes/kubernetes/pull/51377
|
|
|
|
//streamServerCloseCh := service.StreamingServerCloseChan()
|
|
|
|
serverExitMonitorCh := service.ExitMonitorCloseChan()
|
|
|
|
select {
|
|
|
|
// TODO(runcom): enable this after https://github.com/kubernetes/kubernetes/pull/51377
|
|
|
|
//case <-streamServerCloseCh:
|
|
|
|
case <-serverExitMonitorCh:
|
|
|
|
case <-serverCloseCh:
|
2016-10-18 14:48:33 +00:00
|
|
|
}
|
|
|
|
|
2017-09-06 14:02:05 +00:00
|
|
|
service.Shutdown()
|
|
|
|
|
|
|
|
// TODO(runcom): enable this after https://github.com/kubernetes/kubernetes/pull/51377
|
|
|
|
//<-streamServerCloseCh
|
|
|
|
//logrus.Debug("closed stream server")
|
|
|
|
<-serverExitMonitorCh
|
|
|
|
logrus.Debug("closed exit monitor")
|
|
|
|
<-serverCloseCh
|
|
|
|
logrus.Debug("closed main server")
|
|
|
|
|
2016-07-20 01:30:05 +00:00
|
|
|
return nil
|
2016-07-22 20:44:27 +00:00
|
|
|
}
|
2016-07-20 01:30:05 +00:00
|
|
|
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2016-09-19 07:21:14 +00:00
|
|
|
logrus.Fatal(err)
|
2016-07-19 18:53:57 +00:00
|
|
|
}
|
2016-07-08 19:04:00 +00:00
|
|
|
}
|