2018-01-03 07:04: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.
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
package daemon // import "miniflux.app/daemon"
|
2018-01-03 07:04:48 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2018-04-14 23:23:05 +02:00
|
|
|
"runtime"
|
2018-01-03 07:40:26 +01:00
|
|
|
"syscall"
|
2018-01-03 07:04:48 +01:00
|
|
|
"time"
|
|
|
|
|
2018-08-25 06:51:50 +02:00
|
|
|
"miniflux.app/config"
|
|
|
|
"miniflux.app/locale"
|
|
|
|
"miniflux.app/logger"
|
|
|
|
"miniflux.app/reader/feed"
|
|
|
|
"miniflux.app/scheduler"
|
|
|
|
"miniflux.app/storage"
|
2018-01-03 07:04:48 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Run starts the daemon.
|
|
|
|
func Run(cfg *config.Config, store *storage.Storage) {
|
|
|
|
logger.Info("Starting Miniflux...")
|
|
|
|
|
|
|
|
stop := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(stop, os.Interrupt)
|
2018-01-03 07:40:26 +01:00
|
|
|
signal.Notify(stop, syscall.SIGTERM)
|
2018-01-03 07:04:48 +01:00
|
|
|
|
2018-04-14 23:23:05 +02:00
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
var m runtime.MemStats
|
|
|
|
runtime.ReadMemStats(&m)
|
2018-06-20 05:55:29 +02:00
|
|
|
logger.Debug("Sys=%vK, InUse=%vK, HeapInUse=%vK, StackSys=%vK, StackInUse=%vK, GoRoutines=%d, NumCPU=%d",
|
|
|
|
m.Sys/1024, (m.Sys-m.HeapReleased)/1024, m.HeapInuse/1024, m.StackSys/1024, m.StackInuse/1024,
|
|
|
|
runtime.NumGoroutine(), runtime.NumCPU())
|
2018-04-14 23:23:05 +02:00
|
|
|
time.Sleep(30 * time.Second)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-02-28 06:08:32 +01:00
|
|
|
translator := locale.Load()
|
|
|
|
feedHandler := feed.NewFeedHandler(store, translator)
|
2018-01-16 03:08:30 +01:00
|
|
|
pool := scheduler.NewWorkerPool(feedHandler, cfg.WorkerPoolSize())
|
2018-02-28 06:08:32 +01:00
|
|
|
server := newServer(cfg, store, pool, feedHandler, translator)
|
2018-01-03 07:04:48 +01:00
|
|
|
|
|
|
|
scheduler.NewFeedScheduler(
|
|
|
|
store,
|
|
|
|
pool,
|
2018-01-16 03:08:30 +01:00
|
|
|
cfg.PollingFrequency(),
|
|
|
|
cfg.BatchSize(),
|
2018-01-03 07:04:48 +01:00
|
|
|
)
|
|
|
|
|
2018-05-20 01:40:24 +02:00
|
|
|
scheduler.NewCleanupScheduler(store, cfg.CleanupFrequency())
|
2018-01-03 07:04:48 +01:00
|
|
|
|
|
|
|
<-stop
|
|
|
|
logger.Info("Shutting down the server...")
|
2018-04-18 06:50:52 +02:00
|
|
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancel()
|
|
|
|
|
2018-01-03 07:04:48 +01:00
|
|
|
server.Shutdown(ctx)
|
|
|
|
logger.Info("Server gracefully stopped")
|
|
|
|
}
|