Exemplo n.º 1
0
func (r *libcontainerRuntime) Create(id, bundlePath, consolePath string) (runtime.Container, *runtime.IO, error) {
	spec, rspec, err := r.loadSpec(
		filepath.Join(bundlePath, "config.json"),
		filepath.Join(bundlePath, "runtime.json"),
	)
	if err != nil {
		return nil, nil, err
	}
	config, err := r.createLibcontainerConfig(id, bundlePath, spec, rspec)
	if err != nil {
		return nil, nil, err
	}
	container, err := r.factory.Create(id, config)
	if err != nil {
		return nil, nil, fmt.Errorf("create container: %v", err)
	}
	process, err := r.newProcess(spec.Process)
	if err != nil {
		return nil, nil, err
	}
	var rio runtime.IO
	if spec.Process.Terminal {
		if err := process.ConsoleFromPath(consolePath); err != nil {
			return nil, nil, err
		}
	} else {
		uid, err := config.HostUID()
		if err != nil {
			return nil, nil, err
		}
		i, err := process.InitializeIO(uid)
		if err != nil {
			return nil, nil, err
		}
		rio.Stdin = i.Stdin
		rio.Stderr = i.Stderr
		rio.Stdout = i.Stdout
	}
	c := &libcontainerContainer{
		c:                   container,
		additionalProcesses: make(map[int]*libcontainerProcess),
		initProcess: &libcontainerProcess{
			process: process,
			spec:    spec.Process,
		},
		path: bundlePath,
	}
	return c, &rio, nil
}
Exemplo n.º 2
0
func (r *libcontainerRuntime) StartProcess(ci runtime.Container, p specs.Process, consolePath string) (runtime.Process, *runtime.IO, error) {
	c, ok := ci.(*libcontainerContainer)
	if !ok {
		return nil, nil, runtime.ErrInvalidContainerType
	}
	process, err := r.newProcess(p)
	if err != nil {
		return nil, nil, err
	}
	var rio runtime.IO
	if p.Terminal {
		if err := process.ConsoleFromPath(consolePath); err != nil {
			return nil, nil, err
		}
	} else {
		uid, err := c.c.Config().HostUID()
		if err != nil {
			return nil, nil, err
		}
		i, err := process.InitializeIO(uid)
		if err != nil {
			return nil, nil, err
		}
		rio.Stdin = i.Stdin
		rio.Stderr = i.Stderr
		rio.Stdout = i.Stdout
	}
	if err := c.c.Start(process); err != nil {
		return nil, nil, err
	}
	lp := &libcontainerProcess{
		process: process,
		spec:    p,
	}
	pid, err := process.Pid()
	if err != nil {
		return nil, nil, err
	}
	c.additionalProcesses[pid] = lp
	return lp, &rio, nil
}