Add option to disable watchdog and set default timeout to DB healthcheck

This commit is contained in:
Frédéric Guillot 2021-05-23 18:24:57 -07:00 committed by fguillot
parent 36d3b1e9fb
commit e0557d8961
4 changed files with 18 additions and 2 deletions

View file

@ -52,7 +52,7 @@ func startDaemon(store *storage.Storage) {
logger.Error("Unable to send readiness notification to systemd: %v", err)
}
if systemd.HasSystemdWatchdog() {
if config.Opts.HasWatchdog() && systemd.HasSystemdWatchdog() {
logger.Info("Activating Systemd watchdog")
go func() {

View file

@ -64,6 +64,7 @@ const (
defaultMetricsCollector = false
defaultMetricsRefreshInterval = 60
defaultMetricsAllowedNetworks = "127.0.0.1/8"
defaultWatchdog = true
)
var defaultHTTPClientUserAgent = "Mozilla/5.0 (compatible; Miniflux/" + version.Version + "; +https://miniflux.app)"
@ -128,6 +129,7 @@ type Options struct {
metricsCollector bool
metricsRefreshInterval int
metricsAllowedNetworks []string
watchdog bool
}
// NewOptions returns Options with default values.
@ -183,6 +185,7 @@ func NewOptions() *Options {
metricsCollector: defaultMetricsCollector,
metricsRefreshInterval: defaultMetricsRefreshInterval,
metricsAllowedNetworks: []string{defaultMetricsAllowedNetworks},
watchdog: defaultWatchdog,
}
}
@ -457,6 +460,11 @@ func (o *Options) HTTPClientUserAgent() string {
return o.httpClientUserAgent
}
// HasWatchdog returns true if the systemd watchdog is enabled.
func (o *Options) HasWatchdog() bool {
return o.watchdog
}
// SortedOptions returns options as a list of key value pairs, sorted by keys.
func (o *Options) SortedOptions() []*Option {
var keyValues = map[string]interface{}{
@ -512,6 +520,7 @@ func (o *Options) SortedOptions() []*Option {
"SCHEDULER_SERVICE": o.schedulerService,
"SERVER_TIMING_HEADER": o.serverTimingHeader,
"WORKER_POOL_SIZE": o.workerPoolSize,
"WATCHDOG": o.watchdog,
}
keys := make([]string, 0, len(keyValues))

View file

@ -189,6 +189,8 @@ func (p *Parser) parseLines(lines []string) (err error) {
p.opts.metricsAllowedNetworks = parseStringList(value, []string{defaultMetricsAllowedNetworks})
case "FETCH_YOUTUBE_WATCH_TIME":
p.opts.fetchYouTubeWatchTime = parseBool(value, defaultFetchYouTubeWatchTime)
case "WATCHDOG":
p.opts.watchdog = parseBool(value, defaultWatchdog)
}
}

View file

@ -5,7 +5,9 @@
package storage // import "miniflux.app/storage"
import (
"context"
"database/sql"
"time"
)
// Storage handles all operations related to the database.
@ -31,7 +33,10 @@ func (s *Storage) DatabaseVersion() string {
// Ping checks if the database connection works.
func (s *Storage) Ping() error {
return s.db.Ping()
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
return s.db.PingContext(ctx)
}
// DBStats returns database statistics.