From ad32d1c677beceea7826dea9aba9acfcd40533b4 Mon Sep 17 00:00:00 2001 From: Harry Walter Date: Wed, 3 Feb 2016 10:11:43 +0000 Subject: [PATCH 1/3] Setup using env vars as well. Add no retsart option --- main.go | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index d29fd93..1c2d020 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,7 @@ var ( client container.Client pollInterval time.Duration cleanup bool + noRestart bool ) func init() { @@ -49,17 +50,25 @@ func main() { EnvVar: "DOCKER_HOST", }, cli.IntFlag{ - Name: "interval, i", - Usage: "poll interval (in seconds)", - Value: 300, + Name: "interval, i", + Usage: "poll interval (in seconds)", + Value: 300, + EnvVar: "WATCHTOWER_POLL_INTERVAL", }, cli.BoolFlag{ - Name: "no-pull", - Usage: "do not pull new images", + Name: "no-pull", + Usage: "do not pull new images", + EnvVar: "WATCHTOWER_NO_PULL", }, cli.BoolFlag{ - Name: "cleanup", - Usage: "remove old images after updating", + Name: "no-restart", + Usage: "do not restart containers", + EnvVar: "WATCHTOWER_NO_PULL", + }, + cli.BoolFlag{ + Name: "cleanup", + Usage: "remove old images after updating", + EnvVar: "WATCHTOWER_CLEANUP", }, cli.BoolFlag{ Name: "tls", @@ -103,6 +112,7 @@ func before(c *cli.Context) error { pollInterval = time.Duration(c.Int("interval")) * time.Second cleanup = c.GlobalBool("cleanup") + noRestart = c.GlobalBool("no-restart") // Set-up container client tls, err := tlsConfig(c) @@ -125,7 +135,7 @@ func start(c *cli.Context) { for { wg.Add(1) - if err := actions.Update(client, names, cleanup); err != nil { + if err := actions.Update(client, names, cleanup, noRestart); err != nil { fmt.Println(err) } wg.Done() From ac7375a1da8c789da487208bbffb8a464981e2f1 Mon Sep 17 00:00:00 2001 From: Harry Walter Date: Wed, 3 Feb 2016 10:12:26 +0000 Subject: [PATCH 2/3] Skip restarting --- actions/update.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/actions/update.go b/actions/update.go index fe8fc98..a510dde 100644 --- a/actions/update.go +++ b/actions/update.go @@ -34,7 +34,7 @@ func containerFilter(names []string) container.Filter { // used to start those containers have been updated. If a change is detected in // any of the images, the associated containers are stopped and restarted with // the new image. -func Update(client container.Client, names []string, cleanup bool) error { +func Update(client container.Client, names []string, cleanup bool, noRestart bool) error { log.Info("Checking containers for updated images") containers, err := client.ListContainers(containerFilter(names)) @@ -86,8 +86,10 @@ func Update(client container.Client, names []string, cleanup bool) error { } } - if err := client.StartContainer(container); err != nil { - log.Error(err) + if !noRestart { + if err := client.StartContainer(container); err != nil { + log.Error(err) + } } if cleanup { From a74bc9b1b8a2169486ff7413c7348b8ecf93902d Mon Sep 17 00:00:00 2001 From: Harry Walter Date: Tue, 16 Feb 2016 11:35:32 +0000 Subject: [PATCH 3/3] Fix env name --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 1c2d020..56c770a 100644 --- a/main.go +++ b/main.go @@ -63,7 +63,7 @@ func main() { cli.BoolFlag{ Name: "no-restart", Usage: "do not restart containers", - EnvVar: "WATCHTOWER_NO_PULL", + EnvVar: "WATCHTOWER_NO_RESTART", }, cli.BoolFlag{ Name: "cleanup",