2019-06-13 19:25:32 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2019-06-15 13:45:35 +00:00
|
|
|
"log"
|
2019-06-16 21:15:26 +00:00
|
|
|
"time"
|
2019-06-15 13:45:35 +00:00
|
|
|
|
2019-09-01 10:27:06 +00:00
|
|
|
"github.com/Masterminds/semver"
|
2019-06-15 13:58:41 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
|
|
|
"github.com/go-flucky/flucky/pkg/daemon"
|
2019-06-13 19:25:32 +00:00
|
|
|
"github.com/spf13/cobra"
|
2019-10-11 10:36:00 +00:00
|
|
|
"github.com/volker-raschek/go-logger/pkg/logger"
|
2019-06-13 19:25:32 +00:00
|
|
|
)
|
|
|
|
|
2019-09-01 10:27:06 +00:00
|
|
|
var (
|
|
|
|
cleanCacheInterval string
|
|
|
|
compression bool
|
|
|
|
configFile *string
|
|
|
|
round float64
|
|
|
|
temperatureUnit string
|
|
|
|
|
|
|
|
version *semver.Version
|
|
|
|
)
|
2019-06-13 19:25:32 +00:00
|
|
|
|
|
|
|
var daemonCmd = &cobra.Command{
|
|
|
|
Use: "daemon",
|
|
|
|
Short: "Read continuously data from all enabled sensors",
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2019-06-15 12:25:45 +00:00
|
|
|
// read configuration
|
2019-08-19 10:24:08 +00:00
|
|
|
cnf, err := config.Read(*configFile)
|
2019-06-15 13:45:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-06-17 21:37:48 +00:00
|
|
|
duration, err := time.ParseDuration(cleanCacheInterval)
|
2019-06-15 13:45:35 +00:00
|
|
|
if err != nil {
|
2019-06-16 21:15:26 +00:00
|
|
|
log.Fatalf("Can not parse clean cache interval into duration time: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-06-24 15:13:42 +00:00
|
|
|
logger := logger.NewDefaultLogger(logger.LogLevelDebug)
|
2019-09-04 11:37:50 +00:00
|
|
|
daemon.SetLogger(logger)
|
|
|
|
daemon.Start(cnf, duration, compression, round, version)
|
2019-06-13 19:25:32 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-09-04 11:37:50 +00:00
|
|
|
func InitCmd(cmd *cobra.Command, cnfFile *string, sversion *semver.Version) {
|
2019-06-16 11:00:50 +00:00
|
|
|
configFile = cnfFile
|
2019-09-01 10:27:06 +00:00
|
|
|
version = sversion
|
|
|
|
|
2019-06-13 19:25:32 +00:00
|
|
|
cmd.AddCommand(daemonCmd)
|
2019-06-16 21:15:26 +00:00
|
|
|
daemonCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured values")
|
2019-06-17 21:37:48 +00:00
|
|
|
daemonCmd.Flags().StringVar(&cleanCacheInterval, "clean-cache-interval", "5m", "Minute intervall to clean cache and write measured values into logfile")
|
2019-10-11 10:36:00 +00:00
|
|
|
daemonCmd.Flags().Float64Var(&round, "round", 0, "Round values. The value 0 deactivates the function")
|
2019-06-13 19:25:32 +00:00
|
|
|
}
|