Add --revive-stopped flag to start stopped containers after an update (#403)

* Add --revive-stopped flag to start stopped containers after an update

* Update arguments.md
This commit is contained in:
Zois Pagoulatos 2019-11-13 11:16:37 +01:00 committed by Simon Aronsson
parent 63e5049160
commit 2d8507ca31
4 changed files with 23 additions and 3 deletions

View file

@ -93,11 +93,13 @@ func PreRun(cmd *cobra.Command, args []string) {
noPull, _ := f.GetBool("no-pull") noPull, _ := f.GetBool("no-pull")
includeStopped, _ := f.GetBool("include-stopped") includeStopped, _ := f.GetBool("include-stopped")
reviveStopped, _ := f.GetBool("revive-stopped")
removeVolumes, _ := f.GetBool("remove-volumes") removeVolumes, _ := f.GetBool("remove-volumes")
client = container.NewClient( client = container.NewClient(
!noPull, !noPull,
includeStopped, includeStopped,
reviveStopped,
removeVolumes, removeVolumes,
) )

View file

@ -97,6 +97,16 @@ Environment Variable: WATCHTOWER_INCLUDE_STOPPED
Default: false Default: false
``` ```
## Revive stopped
Start any stopped containers that have had their image updated. This argument is only usable with the `--include-stopped` argument.
```
Argument: --revive-stopped
Environment Variable: WATCHTOWER_REVIVE_STOPPED
Type: Boolean
Default: false
```
## Poll interval ## Poll interval
Poll interval (in seconds). This value controls how frequently watchtower will poll for new images. Poll interval (in seconds). This value controls how frequently watchtower will poll for new images.

View file

@ -94,6 +94,12 @@ func RegisterSystemFlags(rootCmd *cobra.Command) {
viper.GetBool("WATCHTOWER_INCLUDE_STOPPED"), viper.GetBool("WATCHTOWER_INCLUDE_STOPPED"),
"Will also include created and exited containers") "Will also include created and exited containers")
flags.BoolP(
"revive-stopped",
"",
viper.GetBool("WATCHTOWER_REVIVE_STOPPED"),
"Will also start stopped containers that were updated, if include-stopped is active")
flags.BoolP( flags.BoolP(
"enable-lifecycle-hooks", "enable-lifecycle-hooks",
"", "",
@ -128,7 +134,7 @@ func RegisterNotificationFlags(rootCmd *cobra.Command) {
"", "",
viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_TO"), viper.GetString("WATCHTOWER_NOTIFICATION_EMAIL_TO"),
"Address to send notification emails to") "Address to send notification emails to")
flags.IntP( flags.IntP(
"notification-email-delay", "notification-email-delay",
"", "",

View file

@ -38,7 +38,7 @@ type Client interface {
// * DOCKER_HOST the docker-engine host to send api requests to // * DOCKER_HOST the docker-engine host to send api requests to
// * DOCKER_TLS_VERIFY whether to verify tls certificates // * DOCKER_TLS_VERIFY whether to verify tls certificates
// * DOCKER_API_VERSION the minimum docker api version to work with // * DOCKER_API_VERSION the minimum docker api version to work with
func NewClient(pullImages bool, includeStopped bool, removeVolumes bool) Client { func NewClient(pullImages bool, includeStopped bool, reviveStopped bool, removeVolumes bool) Client {
cli, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv) cli, err := dockerclient.NewClientWithOpts(dockerclient.FromEnv)
if err != nil { if err != nil {
@ -50,6 +50,7 @@ func NewClient(pullImages bool, includeStopped bool, removeVolumes bool) Client
pullImages: pullImages, pullImages: pullImages,
removeVolumes: removeVolumes, removeVolumes: removeVolumes,
includeStopped: includeStopped, includeStopped: includeStopped,
reviveStopped: reviveStopped,
} }
} }
@ -58,6 +59,7 @@ type dockerClient struct {
pullImages bool pullImages bool
removeVolumes bool removeVolumes bool
includeStopped bool includeStopped bool
reviveStopped bool
} }
func (client dockerClient) ListContainers(fn t.Filter) ([]Container, error) { func (client dockerClient) ListContainers(fn t.Filter) ([]Container, error) {
@ -203,7 +205,7 @@ func (client dockerClient) StartContainer(c Container) (string, error) {
} }
if !c.IsRunning() { if !c.IsRunning() && !client.reviveStopped {
return createdContainer.ID, nil return createdContainer.ID, nil
} }