Skip to content

Commit 8245aad

Browse files
committed
adds option to print output of notify command
1 parent 7c84209 commit 8245aad

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

docker-gen.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var (
2323
version bool
2424
watch bool
2525
notifyCmd string
26+
notifyOutput bool
2627
notifySigHUPContainerID string
2728
onlyExposed bool
2829
onlyPublished bool
@@ -115,6 +116,7 @@ type Config struct {
115116
Dest string
116117
Watch bool
117118
NotifyCmd string
119+
NotifyOutput bool
118120
NotifyContainers map[string]docker.Signal
119121
OnlyExposed bool
120122
OnlyPublished bool
@@ -232,7 +234,13 @@ func runNotifyCmd(config Config) {
232234
out, err := cmd.CombinedOutput()
233235
if err != nil {
234236
log.Printf("Error running notify command: %s, %s\n", config.NotifyCmd, err)
235-
log.Print(string(out))
237+
}
238+
if config.NotifyOutput {
239+
for _, line := range strings.Split(string(out), "\n") {
240+
if line != "" {
241+
log.Printf("[%s]: %s", config.NotifyCmd, line)
242+
}
243+
}
236244
}
237245
}
238246

@@ -393,6 +401,7 @@ func initFlags() {
393401

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

0 commit comments

Comments
 (0)