Skip to content

Commit

Permalink
handle kill event
Browse files Browse the repository at this point in the history
  • Loading branch information
Dustin Blackman committed Jun 18, 2016
1 parent 9fdf8da commit 841a844
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Volume struct {
}

type State struct {
Killing bool
Running bool
}

Expand Down
15 changes: 13 additions & 2 deletions generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down

0 comments on commit 841a844

Please sign in to comment.