Skip to content

Add notify output #142

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

Merged
merged 2 commits into from
Jan 2, 2016
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ Options:
keep blank lines in the output file
-notify restart xyz
run command after template is regenerated (e.g restart xyz)
-notify-output
log the output(stdout/stderr) of notify command
-notify-sighup docker kill -s HUP container-ID
send HUP signal to container. Equivalent to docker kill -s HUP container-ID
-only-exposed
Expand Down
12 changes: 11 additions & 1 deletion docker-gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var (
version bool
watch bool
notifyCmd string
notifyOutput bool
notifySigHUPContainerID string
onlyExposed bool
onlyPublished bool
Expand Down Expand Up @@ -115,6 +116,7 @@ type Config struct {
Dest string
Watch bool
NotifyCmd string
NotifyOutput bool
NotifyContainers map[string]docker.Signal
OnlyExposed bool
OnlyPublished bool
Expand Down Expand Up @@ -232,7 +234,13 @@ func runNotifyCmd(config Config) {
out, err := cmd.CombinedOutput()
if err != nil {
log.Printf("Error running notify command: %s, %s\n", config.NotifyCmd, err)
log.Print(string(out))
}
if config.NotifyOutput {
for _, line := range strings.Split(string(out), "\n") {
if line != "" {
log.Printf("[%s]: %s", config.NotifyCmd, line)
}
}
}
}

Expand Down Expand Up @@ -393,6 +401,7 @@ func initFlags() {

flag.BoolVar(&onlyPublished, "only-published", false,
"only include containers with published ports (implies -only-exposed)")
flag.BoolVar(&notifyOutput, "notify-output", false, "log the output(stdout/stderr) of notify command")
flag.StringVar(&notifyCmd, "notify", "", "run command after template is regenerated (e.g `restart xyz`)")
flag.StringVar(&notifySigHUPContainerID, "notify-sighup", "",
"send HUP signal to container. Equivalent to `docker kill -s HUP container-ID`")
Expand Down Expand Up @@ -435,6 +444,7 @@ func main() {
Dest: flag.Arg(1),
Watch: watch,
NotifyCmd: notifyCmd,
NotifyOutput: notifyOutput,
NotifyContainers: make(map[string]docker.Signal),
OnlyExposed: onlyExposed,
OnlyPublished: onlyPublished,
Expand Down