Skip to content

Commit 7266981

Browse files
authored
Merge pull request #622 from nginx-proxy/notify-multi
feat: allow multiple -notify-sighup / -notify-container
2 parents ec10ca2 + ae220be commit 7266981

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -99,30 +99,33 @@ Options:
9999
run command after template is regenerated (e.g restart xyz)
100100
-notify-output
101101
log the output(stdout/stderr) of notify command
102+
-notify-sighup container-ID
103+
send HUP signal to container.
104+
Equivalent to 'docker kill -s HUP container-ID', or `-notify-container container-ID -notify-signal 1`.
105+
You can pass this option multiple times to send HUP to multiple containers.
102106
-notify-container container-ID
103-
container to send a signal to
107+
send -notify-signal signal (defaults to 1 / HUP) to container.
108+
You can pass this option multiple times to notify multiple containers.
104109
-notify-filter key=value
105110
container filter for notification (e.g -notify-filter name=foo).
106-
You can have multiple of these.
111+
You can pass this option multiple times to combine filters with AND.
107112
https://docs.docker.com/engine/reference/commandline/ps/#filter
108113
-notify-signal signal
109114
signal to send to the -notify-container and -notify-filter. -1 to call docker restart. Defaults to 1 aka. HUP.
110115
All available signals available on the dockerclient
111-
https://github.com/fsouza/go-dockerclient/blob/01804dec8a84d0a77e63611f2b62d33e9bb2b64a/signal.go
112-
-notify-sighup container-ID
113-
send HUP signal to container. Equivalent to 'docker kill -s HUP container-ID', or `-notify-container container-ID -notify-signal 1`
116+
https://github.com/fsouza/go-dockerclient/blob/main/signal.go
114117
-only-exposed
115118
only include containers with exposed ports
116119
-only-published
117120
only include containers with published ports (implies -only-exposed)
118121
-include-stopped
119122
include stopped containers
120123
-tlscacert string
121-
path to TLS CA certificate file (default "/Users/jason/.docker/machine/machines/default/ca.pem")
124+
path to TLS CA certificate file (default "~/.docker/machine/machines/default/ca.pem")
122125
-tlscert string
123-
path to TLS client certificate file (default "/Users/jason/.docker/machine/machines/default/cert.pem")
126+
path to TLS client certificate file (default "~/.docker/machine/machines/default/cert.pem")
124127
-tlskey string
125-
path to TLS client key file (default "/Users/jason/.docker/machine/machines/default/key.pem")
128+
path to TLS client key file (default "~/.docker/machine/machines/default/key.pem")
126129
-tlsverify
127130
verify docker daemon's TLS certicate (default true)
128131
-version

cmd/docker-gen/main.go

+17-13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/signal"
99
"path/filepath"
10+
"slices"
1011
"strings"
1112
"syscall"
1213

@@ -26,8 +27,8 @@ var (
2627
wait string
2728
notifyCmd string
2829
notifyOutput bool
29-
sighupContainerID string
30-
notifyContainerID string
30+
sighupContainerID stringslice
31+
notifyContainerID stringslice
3132
notifyContainerSignal int
3233
notifyContainerFilter mapstringslice = make(mapstringslice)
3334
onlyExposed bool
@@ -49,7 +50,6 @@ func (strings *stringslice) String() string {
4950
}
5051

5152
func (strings *stringslice) Set(value string) error {
52-
// TODO: Throw an error for duplicate `dest`
5353
*strings = append(*strings, value)
5454
return nil
5555
}
@@ -112,12 +112,12 @@ func initFlags() {
112112
flag.BoolVar(&includeStopped, "include-stopped", false, "include stopped containers")
113113
flag.BoolVar(&notifyOutput, "notify-output", false, "log the output(stdout/stderr) of notify command")
114114
flag.StringVar(&notifyCmd, "notify", "", "run command after template is regenerated (e.g `restart xyz`)")
115-
flag.StringVar(&sighupContainerID, "notify-sighup", "",
116-
"send HUP signal to container. Equivalent to docker kill -s HUP `container-ID`")
117-
flag.StringVar(&notifyContainerID, "notify-container", "",
118-
"container to send a signal to")
115+
flag.Var(&sighupContainerID, "notify-sighup",
116+
"send HUP signal to container. Equivalent to docker kill -s HUP `container-ID`. You can pass this option multiple times to send HUP to multiple containers.")
117+
flag.Var(&notifyContainerID, "notify-container",
118+
"send -notify-signal signal (defaults to 1 / HUP) to container. You can pass this option multiple times to notify multiple containers.")
119119
flag.Var(&notifyContainerFilter, "notify-filter",
120-
"container filter for notification (e.g -notify-filter name=foo). You can have multiple of these. https://docs.docker.com/engine/reference/commandline/ps/#filter")
120+
"container filter for notification (e.g -notify-filter name=foo). You can pass this option multiple times to combine filters with AND. https://docs.docker.com/engine/reference/commandline/ps/#filter")
121121
flag.IntVar(&notifyContainerSignal, "notify-signal", int(docker.SIGHUP),
122122
"signal to send to the notify-container and notify-filter. Defaults to SIGHUP")
123123
flag.Var(&configFiles, "config", "config files with template directives. Config files will be merged if this option is specified multiple times.")
@@ -150,6 +150,9 @@ func main() {
150150
os.Exit(1)
151151
}
152152

153+
slices.Sort(configFiles)
154+
configFiles = slices.Compact(configFiles)
155+
153156
if len(configFiles) > 0 {
154157
for _, configFile := range configFiles {
155158
err := loadConfig(configFile)
@@ -176,18 +179,19 @@ func main() {
176179
Interval: interval,
177180
KeepBlankLines: keepBlankLines,
178181
}
179-
if sighupContainerID != "" {
180-
cfg.NotifyContainers[sighupContainerID] = int(syscall.SIGHUP)
182+
for _, id := range sighupContainerID {
183+
cfg.NotifyContainers[id] = int(syscall.SIGHUP)
181184
}
182-
if notifyContainerID != "" {
183-
cfg.NotifyContainers[notifyContainerID] = notifyContainerSignal
185+
for _, id := range notifyContainerID {
186+
cfg.NotifyContainers[id] = notifyContainerSignal
184187
}
185188
if len(notifyContainerFilter) > 0 {
186189
cfg.NotifyContainersFilter = notifyContainerFilter
187190
cfg.NotifyContainersSignal = notifyContainerSignal
188191
}
189192
configs = config.ConfigFile{
190-
Config: []config.Config{cfg}}
193+
Config: []config.Config{cfg},
194+
}
191195
}
192196

193197
all := false

0 commit comments

Comments
 (0)