Example #1
0
// Create creates a bundle in the depot and starts its init process
func (c *Containerizer) Create(log lager.Logger, spec gardener.DesiredContainerSpec) error {
	log = log.Session("containerizer-create", lager.Data{"handle": spec.Handle})

	log.Info("started")
	defer log.Info("finished")

	if err := c.depot.Create(log, spec.Handle, c.bundler.Bundle(spec)); err != nil {
		log.Error("create-failed", err)
		return err
	}

	path, err := c.depot.Lookup(log, spec.Handle)
	if err != nil {
		log.Error("lookup-failed", err)
		return err
	}

	stdoutR, stdoutW := io.Pipe()
	_, err = c.runner.Start(log, path, spec.Handle, garden.ProcessIO{
		Stdout: io.MultiWriter(logging.Writer(log), stdoutW),
		Stderr: logging.Writer(log),
	})
	if err != nil {
		log.Error("start", err)
		return err
	}

	if err := c.startChecker.Check(log, stdoutR); err != nil {
		log.Error("check", err)
		return err
	}

	return nil
}
Example #2
0
func (s *CgroupStarter) mountCgroup(log lager.Logger, cgroupPath, cgroupType string) error {
	log = log.Session("setup-cgroup", lager.Data{
		"path": cgroupPath,
		"type": cgroupType,
	})

	log.Info("started")
	defer log.Info("finished")

	if !s.isMountPoint(cgroupPath) {
		if err := os.MkdirAll(cgroupPath, 0755); err != nil {
			log.Error("mkdir-failed", err)
			return err
		}

		cmd := exec.Command("mount", "-n", "-t", "cgroup", "-o", cgroupType, "cgroup", cgroupPath)
		cmd.Stderr = logging.Writer(log.Session("mount-cgroup-cmd"))
		if err := s.CommandRunner.Run(cmd); err != nil {
			log.Error("mount-cgroup-failed", err)
			return err
		}
	}

	return nil
}