diff --git a/cli/daemon.go b/cli/daemon.go index dc120874..52039452 100644 --- a/cli/daemon.go +++ b/cli/daemon.go @@ -34,7 +34,7 @@ func startDaemon(store *storage.Storage) { go showProcessStatistics() - if config.Opts.HasSchedulerService() { + if config.Opts.HasSchedulerService() && !config.Opts.HasMaintenanceMode() { scheduler.Serve(store, pool) } diff --git a/config/options.go b/config/options.go index 6cae62a1..bb7b5e2c 100644 --- a/config/options.go +++ b/config/options.go @@ -53,6 +53,8 @@ const ( defaultHTTPClientProxy = "" defaultAuthProxyHeader = "" defaultAuthProxyUserCreation = false + defaultMaintenanceMode = false + defaultMaintenanceMessage = "Miniflux is currently under maintenance" ) // Options contains configuration options. @@ -100,6 +102,8 @@ type Options struct { httpClientProxy string authProxyHeader string authProxyUserCreation bool + maintenanceMode bool + maintenanceMessage string } // NewOptions returns Options with default values. @@ -146,6 +150,8 @@ func NewOptions() *Options { httpClientProxy: defaultHTTPClientProxy, authProxyHeader: defaultAuthProxyHeader, authProxyUserCreation: defaultAuthProxyUserCreation, + maintenanceMode: defaultMaintenanceMode, + maintenanceMessage: defaultMaintenanceMessage, } } @@ -154,6 +160,16 @@ func (o *Options) LogDateTime() bool { return o.logDateTime } +// HasMaintenanceMode returns true if maintenance mode is enabled. +func (o *Options) HasMaintenanceMode() bool { + return o.maintenanceMode +} + +// MaintenanceMessage returns maintenance message. +func (o *Options) MaintenanceMessage() string { + return o.maintenanceMessage +} + // HasDebugMode returns true if debug mode is enabled. func (o *Options) HasDebugMode() bool { return o.debug @@ -419,5 +435,7 @@ func (o *Options) String() string { builder.WriteString(fmt.Sprintf("HTTP_CLIENT_PROXY: %v\n", o.httpClientProxy)) builder.WriteString(fmt.Sprintf("AUTH_PROXY_HEADER: %v\n", o.authProxyHeader)) builder.WriteString(fmt.Sprintf("AUTH_PROXY_USER_CREATION: %v\n", o.authProxyUserCreation)) + builder.WriteString(fmt.Sprintf("MAINTENANCE_MODE: %v\n", o.maintenanceMode)) + builder.WriteString(fmt.Sprintf("MAINTENANCE_MESSAGE: %v\n", o.maintenanceMessage)) return builder.String() } diff --git a/config/parser.go b/config/parser.go index e338c0b6..2fb10903 100644 --- a/config/parser.go +++ b/config/parser.go @@ -190,6 +190,10 @@ func (p *Parser) parseLines(lines []string) (err error) { p.opts.authProxyHeader = parseString(value, defaultAuthProxyHeader) case "AUTH_PROXY_USER_CREATION": p.opts.authProxyUserCreation = parseBool(value, defaultAuthProxyUserCreation) + case "MAINTENANCE_MODE": + p.opts.maintenanceMode = parseBool(value, defaultMaintenanceMode) + case "MAINTENANCE_MESSAGE": + p.opts.maintenanceMessage = parseString(value, defaultMaintenanceMessage) } } diff --git a/miniflux.1 b/miniflux.1 index 01a1b5f3..c6d290ce 100644 --- a/miniflux.1 +++ b/miniflux.1 @@ -260,6 +260,12 @@ Proxy authentication HTTP header\&. .TP .B AUTH_PROXY_USER_CREATION Set to 1 to create users based on proxy authentication information\&. +.TP +.B MAINTENANCE_MODE +Set to 1 to enable maintenance mode\&. +.TP +.B MAINTENANCE_MESSAGE +Define a custom maintenance message\&. .SH AUTHORS .P diff --git a/service/httpd/httpd.go b/service/httpd/httpd.go index 21942458..aa9ceca3 100644 --- a/service/httpd/httpd.go +++ b/service/httpd/httpd.go @@ -169,6 +169,14 @@ func setupHandler(store *storage.Storage, feedHandler *feed.Handler, pool *worke router = router.PathPrefix(config.Opts.BasePath()).Subrouter() } + if config.Opts.HasMaintenanceMode() { + router.Use(func(next http.Handler) http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte(config.Opts.MaintenanceMessage())) + }) + }) + } + router.Use(middleware) fever.Serve(router, store)