Add option to enable maintenance mode
This commit is contained in:
parent
a8de067810
commit
df7a6e18fd
5 changed files with 37 additions and 1 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue