Skip to content

Commit f4167a4

Browse files
committed
Merge pull request #142 from bcicen/add-notify-output
Add notify output
2 parents d4bdb13 + 4c1aa16 commit f4167a4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ Options:
9292
keep blank lines in the output file
9393
-notify restart xyz
9494
run command after template is regenerated (e.g restart xyz)
95+
-notify-output
96+
log the output(stdout/stderr) of notify command
9597
-notify-sighup docker kill -s HUP container-ID
9698
send HUP signal to container. Equivalent to docker kill -s HUP container-ID
9799
-only-exposed

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
@@ -128,6 +129,7 @@ type Config struct {
128129
Dest string
129130
Watch bool
130131
NotifyCmd string
132+
NotifyOutput bool
131133
NotifyContainers map[string]docker.Signal
132134
OnlyExposed bool
133135
OnlyPublished bool
@@ -245,7 +247,13 @@ func runNotifyCmd(config Config) {
245247
out, err := cmd.CombinedOutput()
246248
if err != nil {
247249
log.Printf("Error running notify command: %s, %s\n", config.NotifyCmd, err)
248-
log.Print(string(out))
250+
}
251+
if config.NotifyOutput {
252+
for _, line := range strings.Split(string(out), "\n") {
253+
if line != "" {
254+
log.Printf("[%s]: %s", config.NotifyCmd, line)
255+
}
256+
}
249257
}
250258
}
251259

@@ -406,6 +414,7 @@ func initFlags() {
406414

407415
flag.BoolVar(&onlyPublished, "only-published", false,
408416
"only include containers with published ports (implies -only-exposed)")
417+
flag.BoolVar(&notifyOutput, "notify-output", false, "log the output(stdout/stderr) of notify command")
409418
flag.StringVar(&notifyCmd, "notify", "", "run command after template is regenerated (e.g `restart xyz`)")
410419
flag.StringVar(&notifySigHUPContainerID, "notify-sighup", "",
411420
"send HUP signal to container. Equivalent to `docker kill -s HUP container-ID`")
@@ -448,6 +457,7 @@ func main() {
448457
Dest: flag.Arg(1),
449458
Watch: watch,
450459
NotifyCmd: notifyCmd,
460+
NotifyOutput: notifyOutput,
451461
NotifyContainers: make(map[string]docker.Signal),
452462
OnlyExposed: onlyExposed,
453463
OnlyPublished: onlyPublished,

0 commit comments

Comments
 (0)