Skip to content

Commit 841a844

Browse files
author
Dustin Blackman
committed
handle kill event
1 parent 9fdf8da commit 841a844

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

context.go

+1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type Volume struct {
7878
}
7979

8080
type State struct {
81+
Killing bool
8182
Running bool
8283
}
8384

generator.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,22 @@ func (g *generator) generateFromEvents() {
191191
watchers = append(watchers, watcher)
192192

193193
debouncedChan := newDebounceChannel(watcher, config.Wait)
194-
for _ = range debouncedChan {
194+
for event := range debouncedChan {
195195
containers, err := g.getContainers()
196196
if err != nil {
197197
log.Printf("Error listing containers: %s\n", err)
198198
continue
199199
}
200+
201+
if event.Status == "kill" {
202+
for i := len(containers) - 1; i >= 0; i-- {
203+
if containers[i].ID == event.ID {
204+
containers[i].State.Killing = true
205+
break
206+
}
207+
}
208+
}
209+
200210
changed := GenerateFile(config, containers)
201211
if !changed {
202212
log.Printf("Contents of %s did not change. Skipping notification '%s'", config.Dest, config.NotifyCmd)
@@ -270,7 +280,7 @@ func (g *generator) generateFromEvents() {
270280
time.Sleep(10 * time.Second)
271281
break
272282
}
273-
if event.Status == "start" || event.Status == "stop" || event.Status == "die" {
283+
if event.Status == "start" || event.Status == "stop" || event.Status == "die" || event.Status == "kill" {
274284
log.Printf("Received event %s for container %s", event.Status, event.ID[:12])
275285
// fanout event to all watchers
276286
for _, watcher := range watchers {
@@ -375,6 +385,7 @@ func (g *generator) getContainers() ([]*RuntimeContainer, error) {
375385
},
376386
State: State{
377387
Running: container.State.Running,
388+
Killing: false,
378389
},
379390
Name: strings.TrimLeft(container.Name, "/"),
380391
Hostname: container.Config.Hostname,

template.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ func filterRunning(config Config, containers Context) Context {
459459
} else {
460460
filteredContainers := Context{}
461461
for _, container := range containers {
462-
if container.State.Running {
462+
if container.State.Running && !container.State.Killing {
463463
filteredContainers = append(filteredContainers, container)
464464
}
465465
}

0 commit comments

Comments
 (0)