Exemplo n.º 1
0
func (srv *Server) ContainerStart(job *engine.Job) engine.Status {
	if len(job.Args) < 1 {
		return job.Errorf("Usage: %s container_id", job.Name)
	}
	var (
		name      = job.Args[0]
		daemon    = srv.daemon
		container = daemon.Get(name)
	)

	if container == nil {
		return job.Errorf("No such container: %s", name)
	}

	if container.State.IsRunning() {
		return job.Errorf("Container already started")
	}

	// If no environment was set, then no hostconfig was passed.
	if len(job.Environ()) > 0 {
		hostConfig := runconfig.ContainerHostConfigFromJob(job)
		if err := srv.setHostConfig(container, hostConfig); err != nil {
			return job.Error(err)
		}
	}
	if err := container.Start(); err != nil {
		return job.Errorf("Cannot start container %s: %s", name, err)
	}
	srv.LogEvent("start", container.ID, daemon.Repositories().ImageName(container.Image))

	return engine.StatusOK
}
Exemplo n.º 2
0
// FIXME: cleanup and nuke are redundant.
func cleanup(eng *engine.Engine, t *testing.T) error {
	daemon := mkDaemonFromEngine(eng, t)
	for _, container := range daemon.List() {
		container.Kill()
		daemon.Rm(container)
	}
	images, err := daemon.Repositories().Images(&graph.ImagesConfig{})
	if err != nil {
		t.Fatal(err)
	}
	for _, image := range images {
		if image.ID != unitTestImageID {
			eng.Job("image_delete", image.ID).Run()
		}
	}
	return nil
}