Beispiel #1
0
func daemon(id, address, stateDir string, concurrency int, oom bool) error {
	tasks := make(chan *supervisor.StartTask, concurrency*100)
	sv, err := supervisor.New(id, stateDir, tasks, oom)
	if err != nil {
		return err
	}
	wg := &sync.WaitGroup{}
	for i := 0; i < concurrency; i++ {
		wg.Add(1)
		w := supervisor.NewWorker(sv, wg)
		go w.Start()
	}
	// only set containerd as the subreaper if it is not an init process
	if pid := os.Getpid(); pid != 1 {
		logrus.WithFields(logrus.Fields{
			"pid": pid,
		}).Debug("containerd is not init, set as subreaper")
		if err := setSubReaper(); err != nil {
			return err
		}
	}
	// start the signal handler in the background.
	go startSignalHandler(sv)
	if err := sv.Start(); err != nil {
		return err
	}
	if err := os.RemoveAll(address); err != nil {
		return err
	}
	l, err := net.Listen("unix", address)
	if err != nil {
		return err
	}
	s := grpc.NewServer()
	types.RegisterAPIServer(s, server.NewServer(sv))
	protoversion.RegisterAPIServer(
		s,
		protoversion.NewAPIServer(
			containerd.Version,
			protoversion.APIServerOptions{
				DisableLogging: true,
			},
		),
	)
	logrus.Debugf("GRPC API listen on %s", address)
	return s.Serve(l)
}
Beispiel #2
0
func startServer(address string, sv *supervisor.Supervisor) (*grpc.Server, error) {
	if err := os.RemoveAll(address); err != nil {
		return nil, err
	}
	l, err := net.Listen(defaultListenType, address)
	if err != nil {
		return nil, err
	}
	s := grpc.NewServer()
	types.RegisterAPIServer(s, server.NewServer(sv))
	go func() {
		logrus.Debugf("containerd: grpc api on %s", address)
		if err := s.Serve(l); err != nil {
			logrus.WithField("error", err).Fatal("containerd: serve grpc")
		}
	}()
	return s, nil
}
Beispiel #3
0
func daemon(stateDir string, concurrency int, runtimeName string, runtimeArgs []string) (types.APIServer, error) {
	if err := subreaper.Start(); err != nil {
		logrus.WithField("error", err).Error("containerd: start subreaper")
	}
	sv, err := supervisor.New(filepath.Join(stateDir, "containerd"), runtimeName, "", runtimeArgs, 15*time.Second, 500)
	if err != nil {
		return nil, err
	}
	wg := &sync.WaitGroup{}
	for i := 0; i < concurrency; i++ {
		wg.Add(1)
		w := supervisor.NewWorker(sv, wg)
		go w.Start()
	}
	if err := sv.Start(); err != nil {
		return nil, err
	}
	return server.NewServer(sv), nil
}
Beispiel #4
0
func startServer(protocol, address string, sv *supervisor.Supervisor) (*grpc.Server, error) {
	// TODO: We should use TLS.
	// TODO: Add an option for the SocketGroup.
	sockets, err := listeners.Init(protocol, address, "", nil)
	if err != nil {
		return nil, err
	}
	if len(sockets) != 1 {
		return nil, fmt.Errorf("incorrect number of listeners")
	}
	l := sockets[0]
	s := grpc.NewServer()
	types.RegisterAPIServer(s, server.NewServer(sv))
	go func() {
		logrus.Debugf("containerd: grpc api on %s", address)
		if err := s.Serve(l); err != nil {
			logrus.WithField("error", err).Fatal("containerd: serve grpc")
		}
	}()
	return s, nil
}