Exemplo n.º 1
0
func notifyRemoval() {
	log.Debugln("Checking removal notification...")
	if chn.NeedsRemovalNotification() {
		log.Debugln("Needs removal notification. Sending message...")
		chn.GetRemovalChannel() <- struct{}{}
		log.Debugln("Removal notified")
		chn.SetRemovalNotification(false)
	}
}
Exemplo n.º 2
0
func (p *Remove) Run(config Action) error {
	var err error
	stopped := config.Instances.Stopped
	if len(stopped) < 1 {
		log.WithFields(log.Fields{
			"service": config.Service,
			"err":     errNoContainerToRemove,
		}).Errorln("Cannot remove container")

		return errNoContainerToRemove
	}

	ch.SetRemovalNotification(true)

	toRemove := stopped[0]
	// Assumption: I remove only stopped containers; containers have no volume
	err = container.Docker().Client.RemoveContainer(toRemove, false, false)
	if err != nil {
		log.WithFields(log.Fields{
			"service":  config.Service,
			"instance": toRemove,
			"err":      err,
		}).Errorln("Cannot remove container")

		return err
	}

	waitForRemoval()

	log.WithFields(log.Fields{
		"service":  config.Service,
		"instance": toRemove,
	}).Debugln("Removed container")

	return nil
}