@@ -120,7 +120,7 @@ func (r *RuntimeContainer) PublishedAddresses() []Address {
120
120
}
121
121
122
122
func usage () {
123
- println ("Usage: docker-gen [-config file] [-watch=false] [-notify=\" restart xyz\" ] [-interval=0] [-endpoint tcp|unix://..] <template> [<dest>]" )
123
+ println ("Usage: docker-gen [-config file] [-watch=false] [-notify=\" restart xyz\" ][-notify= \" restart-container container-ID \" ] [-interval=0] [-endpoint tcp|unix://..] <template> [<dest>]" )
124
124
}
125
125
126
126
func generateFromContainers (client * docker.Client ) {
@@ -135,22 +135,33 @@ func generateFromContainers(client *docker.Client) {
135
135
log .Printf ("Contents of %s did not change. Skipping notification '%s'" , config .Dest , config .NotifyCmd )
136
136
continue
137
137
}
138
- runNotifyCmd (config )
138
+ runNotifyCmd (client , config )
139
139
}
140
140
}
141
141
142
- func runNotifyCmd (config Config ) {
142
+ func runNotifyCmd (client * docker. Client , config Config ) {
143
143
if config .NotifyCmd == "" {
144
144
return
145
145
}
146
146
147
- log .Printf ("Running '%s'" , config .NotifyCmd )
148
147
args := strings .Split (config .NotifyCmd , " " )
149
- cmd := exec .Command (args [0 ], args [1 :]... )
150
- out , err := cmd .CombinedOutput ()
151
- if err != nil {
152
- log .Printf ("error running notify command: %s, %s\n " , config .NotifyCmd , err )
153
- log .Print (string (out ))
148
+ if args [0 ] == "restart-container" {
149
+ log .Printf ("Restarting container '%s'" , args [1 ])
150
+ err := client .KillContainer (docker.KillContainerOptions {
151
+ ID : args [1 ],
152
+ Signal : docker .SIGHUP ,
153
+ })
154
+ if err != nil {
155
+ log .Printf ("Error restarting container: %s" , err )
156
+ }
157
+ } else {
158
+ log .Printf ("Running '%s'" , config .NotifyCmd )
159
+ cmd := exec .Command (args [0 ], args [1 :]... )
160
+ out , err := cmd .CombinedOutput ()
161
+ if err != nil {
162
+ log .Printf ("error running notify command: %s, %s\n " , config .NotifyCmd , err )
163
+ log .Print (string (out ))
164
+ }
154
165
}
155
166
}
156
167
@@ -186,7 +197,7 @@ func generateAtInterval(client *docker.Client, configs ConfigFile) {
186
197
}
187
198
// ignore changed return value. always run notify command
188
199
generateFile (configCopy , containers )
189
- runNotifyCmd (configCopy )
200
+ runNotifyCmd (client , configCopy )
190
201
case <- quit :
191
202
ticker .Stop ()
192
203
return
0 commit comments