Skip to content

Commit e14cc29

Browse files
jinnatarpiksel
andauthored
feat: improve HTTP API logging, honor no-startup-message (#1091)
Co-authored-by: nils måsén <[email protected]>
1 parent b3b45ab commit e14cc29

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

cmd/root.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ func Run(c *cobra.Command, names []string) {
191191
if enableUpdateAPI {
192192
updateHandler := update.New(func() { runUpdatesWithNotifications(filter) }, updateLock)
193193
httpAPI.RegisterFunc(updateHandler.Path, updateHandler.Handle)
194+
// If polling isn't enabled the scheduler is never started and
195+
// we need to trigger the startup messages manually.
196+
if !unblockHTTPAPI {
197+
writeStartupMessage(c, time.Time{}, filterDesc)
198+
}
194199
}
195200

196201
if enableMetricsAPI {
@@ -261,6 +266,7 @@ func formatDuration(d time.Duration) string {
261266

262267
func writeStartupMessage(c *cobra.Command, sched time.Time, filtering string) {
263268
noStartupMessage, _ := c.PersistentFlags().GetBool("no-startup-message")
269+
enableUpdateAPI, _ := c.PersistentFlags().GetBool("http-api-update")
264270

265271
var startupLog *log.Entry
266272
if noStartupMessage {
@@ -286,8 +292,15 @@ func writeStartupMessage(c *cobra.Command, sched time.Time, filtering string) {
286292
until := formatDuration(time.Until(sched))
287293
startupLog.Info("Scheduling first run: " + sched.Format("2006-01-02 15:04:05 -0700 MST"))
288294
startupLog.Info("Note that the first check will be performed in " + until)
295+
} else if runOnce, _ := c.PersistentFlags().GetBool("run-once"); runOnce {
296+
startupLog.Info("Running a one time update.")
289297
} else {
290-
startupLog.Info("Running a one time update.")
298+
startupLog.Info("Periodic runs are not enabled.")
299+
}
300+
301+
if enableUpdateAPI {
302+
// TODO: make listen port configurable
303+
startupLog.Info("The HTTP API is enabled at :8080.")
291304
}
292305

293306
if !noStartupMessage {

pkg/api/api.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ func (api *API) Start(block bool) error {
6262
log.Fatal(tokenMissingMsg)
6363
}
6464

65-
log.Info("Watchtower HTTP API started.")
6665
if block {
6766
runHTTPServer()
6867
} else {
@@ -74,6 +73,5 @@ func (api *API) Start(block bool) error {
7473
}
7574

7675
func runHTTPServer() {
77-
log.Info("Serving HTTP")
7876
log.Fatal(http.ListenAndServe(":8080", nil))
7977
}

0 commit comments

Comments
 (0)