Skip to content

Handle kill event #202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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