From 841a844e8942deec180ad39805c1779cc40f267a Mon Sep 17 00:00:00 2001 From: Dustin Blackman Date: Fri, 17 Jun 2016 16:08:09 -0400 Subject: [PATCH] handle kill event --- context.go | 1 + generator.go | 15 +++++++++++++-- template.go | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index da535fe2..658c8949 100644 --- a/context.go +++ b/context.go @@ -78,6 +78,7 @@ type Volume struct { } type State struct { + Killing bool Running bool } diff --git a/generator.go b/generator.go index bf68be66..d99ea5cc 100644 --- a/generator.go +++ b/generator.go @@ -191,12 +191,22 @@ func (g *generator) generateFromEvents() { watchers = append(watchers, watcher) debouncedChan := newDebounceChannel(watcher, config.Wait) - for _ = range debouncedChan { + for event := range debouncedChan { containers, err := g.getContainers() if err != nil { log.Printf("Error listing containers: %s\n", err) continue } + + if event.Status == "kill" { + for i := len(containers) - 1; i >= 0; i-- { + if containers[i].ID == event.ID { + containers[i].State.Killing = true + break + } + } + } + changed := GenerateFile(config, containers) if !changed { log.Printf("Contents of %s did not change. Skipping notification '%s'", config.Dest, config.NotifyCmd) @@ -270,7 +280,7 @@ func (g *generator) generateFromEvents() { time.Sleep(10 * time.Second) break } - if event.Status == "start" || event.Status == "stop" || event.Status == "die" { + if event.Status == "start" || event.Status == "stop" || event.Status == "die" || event.Status == "kill" { log.Printf("Received event %s for container %s", event.Status, event.ID[:12]) // fanout event to all watchers for _, watcher := range watchers { @@ -375,6 +385,7 @@ func (g *generator) getContainers() ([]*RuntimeContainer, error) { }, State: State{ Running: container.State.Running, + Killing: false, }, Name: strings.TrimLeft(container.Name, "/"), Hostname: container.Config.Hostname, diff --git a/template.go b/template.go index 41add914..367e1ff9 100644 --- a/template.go +++ b/template.go @@ -459,7 +459,7 @@ func filterRunning(config Config, containers Context) Context { } else { filteredContainers := Context{} for _, container := range containers { - if container.State.Running { + if container.State.Running && !container.State.Killing { filteredContainers = append(filteredContainers, container) } }