Exemplo n.º 1
0
Arquivo: run.go Projeto: dnephin/dobi
func (t *Task) forwardSignals(client client.DockerClient, containerID string) chan<- os.Signal {
	chanSig := make(chan os.Signal, 128)

	// TODO: not all of these exist on windows?
	signal.Notify(chanSig, syscall.SIGINT, syscall.SIGTERM)

	kill := func(sig os.Signal) {
		t.logger().WithFields(log.Fields{"signal": sig}).Debug("received")

		intSig, ok := sig.(syscall.Signal)
		if !ok {
			t.logger().WithFields(log.Fields{"signal": sig}).Warnf(
				"Failed to convert signal from %T", sig)
			return
		}

		if err := client.KillContainer(docker.KillContainerOptions{
			ID:     containerID,
			Signal: docker.Signal(intSig),
		}); err != nil {
			t.logger().WithFields(log.Fields{"signal": sig}).Warnf(
				"Failed to send signal: %s", err)
		}
	}

	go func() {
		for sig := range chanSig {
			kill(sig)
		}
	}()
	return chanSig
}
Exemplo n.º 2
0
Arquivo: run.go Projeto: dnephin/dobi
func (t *Task) wait(client client.DockerClient, containerID string) error {
	status, err := client.WaitContainer(containerID)
	if err != nil {
		return fmt.Errorf("failed to wait on container exit: %s", err)
	}
	if status != 0 {
		return fmt.Errorf("exited with non-zero status code %d", status)
	}
	return nil
}
Exemplo n.º 3
0
// RemoveContainer removes a container
func RemoveContainer(logger *log.Entry, client client.DockerClient, containerID string, expectContainer bool) {
	logger.Debug("Removing container")
	err := client.RemoveContainer(docker.RemoveContainerOptions{
		ID:            containerID,
		RemoveVolumes: true,
	})
	switch err.(type) {
	case *docker.NoSuchContainer:
		if !expectContainer {
			return
		}
	case nil:
		return
	}
	logger.WithFields(log.Fields{"container": containerID}).Warnf(
		"Failed to remove container: %s", err)
}