Exemple #1
0
func (r *OCIRuntime) Delete(ctx context.Context, c *execution.Container) error {
	id := c.ID()
	if err := r.runc.Delete(ctx, id); err != nil {
		return err
	}
	c.StateDir().Delete()
	r.ios[id].cleanup()
	delete(r.ios, id)
	return nil
}
Exemple #2
0
func (r *OCIRuntime) StartProcess(ctx context.Context, c *execution.Container, o execution.StartProcessOpts) (p execution.Process, err error) {
	oio, err := newOIO(o.Stdin, o.Stdout, o.Stderr, o.Console)
	if err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			oio.cleanup()
		}
	}()

	procStateDir, err := c.StateDir().NewProcess(o.ID)
	if err != nil {
		return nil, err
	}
	defer func() {
		if err != nil {
			c.StateDir().DeleteProcess(o.ID)
		}
	}()

	pidFile := filepath.Join(procStateDir, PidFilename)
	if err := r.runc.Exec(ctx, c.ID(), o.Spec, &runc.ExecOpts{
		PidFile: pidFile,
		Detach:  false,
		Console: oio.console,
		Cwd:     o.Spec.Cwd,
		IO:      oio.rio,
	}); err != nil {
		return nil, err
	}

	process, err := newProcess(o.ID, procStateDir, execution.Running)
	if err != nil {
		return nil, err
	}

	c.AddProcess(process, false)

	r.ios[fmt.Sprintf("%s-%s", c.ID(), process.ID())] = oio

	return process, nil
}
Exemple #3
0
func (r *OCIRuntime) DeleteProcess(ctx context.Context, c *execution.Container, id string) error {
	ioID := fmt.Sprintf("%s-%s", c.ID(), id)
	r.ios[ioID].cleanup()
	delete(r.ios, ioID)
	return c.StateDir().DeleteProcess(id)
}