mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
fix depends on behavior and simplify some of its logic (#908)
* fix depends on behavior and simplify some of its logic * fix comments
This commit is contained in:
parent
4142f7966a
commit
3de202a965
5 changed files with 83 additions and 29 deletions
24
cmd/root.go
24
cmd/root.go
|
@ -154,9 +154,18 @@ func Run(c *cobra.Command, names []string) {
|
|||
runOnce, _ := c.PersistentFlags().GetBool("run-once")
|
||||
enableUpdateAPI, _ := c.PersistentFlags().GetBool("http-api-update")
|
||||
enableMetricsAPI, _ := c.PersistentFlags().GetBool("http-api-metrics")
|
||||
|
||||
apiToken, _ := c.PersistentFlags().GetString("http-api-token")
|
||||
|
||||
if rollingRestart && monitorOnly {
|
||||
log.Fatal("Rolling restarts is not compatible with the global monitor only flag")
|
||||
}
|
||||
|
||||
awaitDockerClient()
|
||||
|
||||
if err := actions.CheckForSanity(client, filter, rollingRestart); err != nil {
|
||||
logNotifyExit(err)
|
||||
}
|
||||
|
||||
if runOnce {
|
||||
writeStartupMessage(c, time.Time{}, filterDesc)
|
||||
runUpdatesWithNotifications(filter)
|
||||
|
@ -166,7 +175,7 @@ func Run(c *cobra.Command, names []string) {
|
|||
}
|
||||
|
||||
if err := actions.CheckForMultipleWatchtowerInstances(client, cleanup, scope); err != nil {
|
||||
log.Fatal(err)
|
||||
logNotifyExit(err)
|
||||
}
|
||||
|
||||
httpAPI := api.New(apiToken)
|
||||
|
@ -192,6 +201,17 @@ func Run(c *cobra.Command, names []string) {
|
|||
os.Exit(1)
|
||||
}
|
||||
|
||||
func logNotifyExit(err error) {
|
||||
log.Error(err)
|
||||
notifier.Close()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func awaitDockerClient() {
|
||||
log.Debug("Sleeping for a second to ensure the docker api client has been properly initialized.")
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
|
||||
func formatDuration(d time.Duration) string {
|
||||
sb := strings.Builder{}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue