Skip to content

Commit a5abae3

Browse files
committed
Allow more notify and restart options nginx-proxy#283 nginx-proxy#283
1 parent 214ff58 commit a5abae3

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,13 @@ Options:
9191
run command after template is regenerated (e.g restart xyz)
9292
-notify-output
9393
log the output(stdout/stderr) of notify command
94+
-notify-container container-ID
95+
container to send a signal to
96+
-notify-signal signal
97+
signal to send to the -notify-container. -1 to call docker restart. Defaults to 1 aka. HUP.
98+
All available signals available on the [dockerclient](https://github.com/fsouza/go-dockerclient/blob/01804dec8a84d0a77e63611f2b62d33e9bb2b64a/signal.go)
9499
-notify-sighup container-ID
95-
send HUP signal to container. Equivalent to 'docker kill -s HUP container-ID'
100+
send HUP signal to container. Equivalent to 'docker kill -s HUP container-ID' or `-notify-container container-ID -notify-signal 1`
96101
-only-exposed
97102
only include containers with exposed ports
98103
-only-published

cmd/docker-gen/main.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ var (
2424
wait string
2525
notifyCmd string
2626
notifyOutput bool
27-
notifySigHUPContainerID string
27+
notifyContainerID string
28+
notifyContainerSignal int
2829
onlyExposed bool
2930
onlyPublished bool
3031
includeStopped bool
@@ -97,8 +98,9 @@ func initFlags() {
9798
flag.BoolVar(&includeStopped, "include-stopped", false, "include stopped containers")
9899
flag.BoolVar(&notifyOutput, "notify-output", false, "log the output(stdout/stderr) of notify command")
99100
flag.StringVar(&notifyCmd, "notify", "", "run command after template is regenerated (e.g `restart xyz`)")
100-
flag.StringVar(&notifySigHUPContainerID, "notify-sighup", "",
101-
"send HUP signal to container. Equivalent to docker kill -s HUP `container-ID`")
101+
flag.StringVar(&notifyContainerID, "notify-sighup", "", "send HUP signal to container. Equivalent to docker kill -s HUP `container-ID`")
102+
flag.StringVar(&notifyContainerID, "notify-container", "", "container to send a signal to")
103+
flag.IntVar(&notifyContainerSignal, "notify-signal", int(docker.SIGHUP), "signal to send to the notify-container. Defaults to SIGHUP")
102104
flag.Var(&configFiles, "config", "config files with template directives. Config files will be merged if this option is specified multiple times.")
103105
flag.IntVar(&interval, "interval", 0, "notify command interval (secs)")
104106
flag.BoolVar(&keepBlankLines, "keep-blank-lines", false, "keep blank lines in the output file")
@@ -155,8 +157,8 @@ func main() {
155157
Interval: interval,
156158
KeepBlankLines: keepBlankLines,
157159
}
158-
if notifySigHUPContainerID != "" {
159-
config.NotifyContainers[notifySigHUPContainerID] = docker.SIGHUP
160+
if notifyContainerID != "" {
161+
config.NotifyContainers[notifyContainerID] = docker.Signal(notifyContainerSignal)
160162
}
161163
configs = dockergen.ConfigFile{
162164
Config: []dockergen.Config{config}}

generator.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,14 @@ func (g *generator) sendSignalToContainer(config Config) {
331331

332332
for container, signal := range config.NotifyContainers {
333333
log.Printf("Sending container '%s' signal '%v'", container, signal)
334+
335+
if signal == -1 {
336+
if err := g.Client.RestartContainer(container, 10); err != nil {
337+
log.Printf("Error sending restarting container: %s", err)
338+
}
339+
return
340+
}
341+
334342
killOpts := docker.KillContainerOptions{
335343
ID: container,
336344
Signal: signal,

0 commit comments

Comments
 (0)