mirror of
https://github.com/containrrr/watchtower.git
synced 2025-09-21 21:30:48 +02:00
feat: improve HTTP API logging, honor no-startup-message (#1091)
Co-authored-by: nils måsén <nils@piksel.se>
This commit is contained in:
parent
b3b45ab19e
commit
e14cc292ed
2 changed files with 14 additions and 3 deletions
15
cmd/root.go
15
cmd/root.go
|
@ -191,6 +191,11 @@ func Run(c *cobra.Command, names []string) {
|
||||||
if enableUpdateAPI {
|
if enableUpdateAPI {
|
||||||
updateHandler := update.New(func() { runUpdatesWithNotifications(filter) }, updateLock)
|
updateHandler := update.New(func() { runUpdatesWithNotifications(filter) }, updateLock)
|
||||||
httpAPI.RegisterFunc(updateHandler.Path, updateHandler.Handle)
|
httpAPI.RegisterFunc(updateHandler.Path, updateHandler.Handle)
|
||||||
|
// If polling isn't enabled the scheduler is never started and
|
||||||
|
// we need to trigger the startup messages manually.
|
||||||
|
if !unblockHTTPAPI {
|
||||||
|
writeStartupMessage(c, time.Time{}, filterDesc)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if enableMetricsAPI {
|
if enableMetricsAPI {
|
||||||
|
@ -261,6 +266,7 @@ func formatDuration(d time.Duration) string {
|
||||||
|
|
||||||
func writeStartupMessage(c *cobra.Command, sched time.Time, filtering string) {
|
func writeStartupMessage(c *cobra.Command, sched time.Time, filtering string) {
|
||||||
noStartupMessage, _ := c.PersistentFlags().GetBool("no-startup-message")
|
noStartupMessage, _ := c.PersistentFlags().GetBool("no-startup-message")
|
||||||
|
enableUpdateAPI, _ := c.PersistentFlags().GetBool("http-api-update")
|
||||||
|
|
||||||
var startupLog *log.Entry
|
var startupLog *log.Entry
|
||||||
if noStartupMessage {
|
if noStartupMessage {
|
||||||
|
@ -286,8 +292,15 @@ func writeStartupMessage(c *cobra.Command, sched time.Time, filtering string) {
|
||||||
until := formatDuration(time.Until(sched))
|
until := formatDuration(time.Until(sched))
|
||||||
startupLog.Info("Scheduling first run: " + sched.Format("2006-01-02 15:04:05 -0700 MST"))
|
startupLog.Info("Scheduling first run: " + sched.Format("2006-01-02 15:04:05 -0700 MST"))
|
||||||
startupLog.Info("Note that the first check will be performed in " + until)
|
startupLog.Info("Note that the first check will be performed in " + until)
|
||||||
|
} else if runOnce, _ := c.PersistentFlags().GetBool("run-once"); runOnce {
|
||||||
|
startupLog.Info("Running a one time update.")
|
||||||
} else {
|
} else {
|
||||||
startupLog.Info("Running a one time update.")
|
startupLog.Info("Periodic runs are not enabled.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if enableUpdateAPI {
|
||||||
|
// TODO: make listen port configurable
|
||||||
|
startupLog.Info("The HTTP API is enabled at :8080.")
|
||||||
}
|
}
|
||||||
|
|
||||||
if !noStartupMessage {
|
if !noStartupMessage {
|
||||||
|
|
|
@ -62,7 +62,6 @@ func (api *API) Start(block bool) error {
|
||||||
log.Fatal(tokenMissingMsg)
|
log.Fatal(tokenMissingMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Info("Watchtower HTTP API started.")
|
|
||||||
if block {
|
if block {
|
||||||
runHTTPServer()
|
runHTTPServer()
|
||||||
} else {
|
} else {
|
||||||
|
@ -74,6 +73,5 @@ func (api *API) Start(block bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runHTTPServer() {
|
func runHTTPServer() {
|
||||||
log.Info("Serving HTTP")
|
|
||||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue