Skip to content

Commit 99346c4

Browse files
author
Dustin Blackman
committed
handle kill event
1 parent 9fdf8da commit 99346c4

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

context.go

Lines changed: 1 addition & 0 deletions
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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,21 @@ 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+
}
206+
}
207+
}
208+
200209
changed := GenerateFile(config, containers)
201210
if !changed {
202211
log.Printf("Contents of %s did not change. Skipping notification '%s'", config.Dest, config.NotifyCmd)
@@ -270,7 +279,7 @@ func (g *generator) generateFromEvents() {
270279
time.Sleep(10 * time.Second)
271280
break
272281
}
273-
if event.Status == "start" || event.Status == "stop" || event.Status == "die" {
282+
if event.Status == "start" || event.Status == "stop" || event.Status == "die" || event.Status == "kill" {
274283
log.Printf("Received event %s for container %s", event.Status, event.ID[:12])
275284
// fanout event to all watchers
276285
for _, watcher := range watchers {
@@ -375,6 +384,7 @@ func (g *generator) getContainers() ([]*RuntimeContainer, error) {
375384
},
376385
State: State{
377386
Running: container.State.Running,
387+
Killing: false,
378388
},
379389
Name: strings.TrimLeft(container.Name, "/"),
380390
Hostname: container.Config.Hostname,

template.go

Lines changed: 1 addition & 1 deletion
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)