Browse Source

Add option to enable maintenance mode

Frédéric Guillot 5 years ago
parent
commit
df7a6e18fd
5 changed files with 37 additions and 1 deletions
  1. 1 1
      cli/daemon.go
  2. 18 0
      config/options.go
  3. 4 0
      config/parser.go
  4. 6 0
      miniflux.1
  5. 8 0
      service/httpd/httpd.go

+ 1 - 1
cli/daemon.go

@@ -34,7 +34,7 @@ func startDaemon(store *storage.Storage) {
 
 
 	go showProcessStatistics()
 	go showProcessStatistics()
 
 
-	if config.Opts.HasSchedulerService() {
+	if config.Opts.HasSchedulerService() && !config.Opts.HasMaintenanceMode() {
 		scheduler.Serve(store, pool)
 		scheduler.Serve(store, pool)
 	}
 	}
 
 

+ 18 - 0
config/options.go

@@ -53,6 +53,8 @@ const (
 	defaultHTTPClientProxy                    = ""
 	defaultHTTPClientProxy                    = ""
 	defaultAuthProxyHeader                    = ""
 	defaultAuthProxyHeader                    = ""
 	defaultAuthProxyUserCreation              = false
 	defaultAuthProxyUserCreation              = false
+	defaultMaintenanceMode                    = false
+	defaultMaintenanceMessage                 = "Miniflux is currently under maintenance"
 )
 )
 
 
 // Options contains configuration options.
 // Options contains configuration options.
@@ -100,6 +102,8 @@ type Options struct {
 	httpClientProxy                    string
 	httpClientProxy                    string
 	authProxyHeader                    string
 	authProxyHeader                    string
 	authProxyUserCreation              bool
 	authProxyUserCreation              bool
+	maintenanceMode                    bool
+	maintenanceMessage                 string
 }
 }
 
 
 // NewOptions returns Options with default values.
 // NewOptions returns Options with default values.
@@ -146,6 +150,8 @@ func NewOptions() *Options {
 		httpClientProxy:                    defaultHTTPClientProxy,
 		httpClientProxy:                    defaultHTTPClientProxy,
 		authProxyHeader:                    defaultAuthProxyHeader,
 		authProxyHeader:                    defaultAuthProxyHeader,
 		authProxyUserCreation:              defaultAuthProxyUserCreation,
 		authProxyUserCreation:              defaultAuthProxyUserCreation,
+		maintenanceMode:                    defaultMaintenanceMode,
+		maintenanceMessage:                 defaultMaintenanceMessage,
 	}
 	}
 }
 }
 
 
@@ -154,6 +160,16 @@ func (o *Options) LogDateTime() bool {
 	return o.logDateTime
 	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.
 // HasDebugMode returns true if debug mode is enabled.
 func (o *Options) HasDebugMode() bool {
 func (o *Options) HasDebugMode() bool {
 	return o.debug
 	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("HTTP_CLIENT_PROXY: %v\n", o.httpClientProxy))
 	builder.WriteString(fmt.Sprintf("AUTH_PROXY_HEADER: %v\n", o.authProxyHeader))
 	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("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()
 	return builder.String()
 }
 }

+ 4 - 0
config/parser.go

@@ -190,6 +190,10 @@ func (p *Parser) parseLines(lines []string) (err error) {
 			p.opts.authProxyHeader = parseString(value, defaultAuthProxyHeader)
 			p.opts.authProxyHeader = parseString(value, defaultAuthProxyHeader)
 		case "AUTH_PROXY_USER_CREATION":
 		case "AUTH_PROXY_USER_CREATION":
 			p.opts.authProxyUserCreation = parseBool(value, defaultAuthProxyUserCreation)
 			p.opts.authProxyUserCreation = parseBool(value, defaultAuthProxyUserCreation)
+		case "MAINTENANCE_MODE":
+			p.opts.maintenanceMode = parseBool(value, defaultMaintenanceMode)
+		case "MAINTENANCE_MESSAGE":
+			p.opts.maintenanceMessage = parseString(value, defaultMaintenanceMessage)
 		}
 		}
 	}
 	}
 
 

+ 6 - 0
miniflux.1

@@ -260,6 +260,12 @@ Proxy authentication HTTP header\&.
 .TP
 .TP
 .B AUTH_PROXY_USER_CREATION
 .B AUTH_PROXY_USER_CREATION
 Set to 1 to create users based on proxy authentication information\&.
 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
 .SH AUTHORS
 .P
 .P

+ 8 - 0
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()
 		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)
 	router.Use(middleware)
 
 
 	fever.Serve(router, store)
 	fever.Serve(router, store)