2018-11-12 00:32:48 +01:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package cli // import "miniflux.app/cli"
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-11-12 00:54:19 +01:00
|
|
|
"net/http"
|
2018-11-12 00:32:48 +01:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"miniflux.app/config"
|
|
|
|
"miniflux.app/logger"
|
2020-09-28 01:01:06 +02:00
|
|
|
"miniflux.app/metric"
|
2018-11-12 00:32:48 +01:00
|
|
|
"miniflux.app/reader/feed"
|
|
|
|
"miniflux.app/service/httpd"
|
2019-06-02 03:18:09 +02:00
|
|
|
"miniflux.app/service/scheduler"
|
2018-11-12 00:32:48 +01:00
|
|
|
"miniflux.app/storage"
|
|
|
|
"miniflux.app/worker"
|
|
|
|
)
|
|
|
|
|
2019-06-02 03:18:09 +02:00
|
|
|
func startDaemon(store *storage.Storage) {
|
2018-11-12 00:32:48 +01:00
|
|
|
logger.Info("Starting Miniflux...")
|
|
|
|
|
|
|
|
stop := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(stop, os.Interrupt)
|
|
|
|
signal.Notify(stop, syscall.SIGTERM)
|
|
|
|
|
|
|
|
feedHandler := feed.NewFeedHandler(store)
|
2019-06-02 03:18:09 +02:00
|
|
|
pool := worker.NewPool(feedHandler, config.Opts.WorkerPoolSize())
|
2018-11-12 00:32:48 +01:00
|
|
|
|
2020-09-13 03:31:45 +02:00
|
|
|
if config.Opts.HasSchedulerService() && !config.Opts.HasMaintenanceMode() {
|
2019-06-02 03:18:09 +02:00
|
|
|
scheduler.Serve(store, pool)
|
2018-11-12 00:54:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var httpServer *http.Server
|
2019-06-02 03:18:09 +02:00
|
|
|
if config.Opts.HasHTTPService() {
|
|
|
|
httpServer = httpd.Serve(store, pool, feedHandler)
|
2018-11-12 00:54:19 +01:00
|
|
|
}
|
2018-11-12 00:32:48 +01:00
|
|
|
|
2020-09-28 01:01:06 +02:00
|
|
|
if config.Opts.HasMetricsCollector() {
|
|
|
|
collector := metric.NewCollector(store, config.Opts.MetricsRefreshInterval())
|
|
|
|
go collector.GatherStorageMetrics()
|
|
|
|
}
|
|
|
|
|
2018-11-12 00:32:48 +01:00
|
|
|
<-stop
|
|
|
|
logger.Info("Shutting down the process...")
|
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2018-11-12 00:54:19 +01:00
|
|
|
if httpServer != nil {
|
|
|
|
httpServer.Shutdown(ctx)
|
|
|
|
}
|
|
|
|
|
2018-11-12 00:32:48 +01:00
|
|
|
logger.Info("Process gracefully stopped")
|
|
|
|
}
|