2020-05-17 11:00:51 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/volker-raschek/flucky/pkg/config"
|
|
|
|
"github.com/volker-raschek/flucky/pkg/daemon"
|
|
|
|
"github.com/volker-raschek/go-logger/pkg/logger"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InitCmd initialize all daemon subcommands
|
|
|
|
func InitCmd(cmd *cobra.Command) error {
|
|
|
|
daemonCmd := &cobra.Command{
|
|
|
|
Use: "daemon",
|
|
|
|
Short: "Read continuously data from all enabled sensors",
|
|
|
|
Example: "flucky daemon",
|
|
|
|
RunE: run,
|
|
|
|
}
|
|
|
|
|
|
|
|
daemonCmd.Flags().Bool("compression", true, "Compress measured values")
|
2020-06-01 10:41:48 +00:00
|
|
|
daemonCmd.Flags().Uint("cached-values", 500, "Number of cached values before saveing into the backend")
|
2020-05-17 11:00:51 +00:00
|
|
|
daemonCmd.Flags().Float64("round", 0.5, "Round values. The value 0 deactivates the function")
|
|
|
|
cmd.AddCommand(daemonCmd)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func run(cmd *cobra.Command, args []string) error {
|
|
|
|
configFile, err := cmd.Flags().GetString("config")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("No config file defined: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// logLevel, err := cmd.Flags().GetString("loglevel")
|
|
|
|
// if err != nil {
|
|
|
|
// return fmt.Errorf("No loglevel defined: %v", err)
|
|
|
|
// }
|
|
|
|
|
|
|
|
flogger := logger.NewDefaultLogger(logger.LogLevelDebug)
|
|
|
|
|
|
|
|
cnf, err := config.Read(configFile)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return daemon.Start(cnf, flogger)
|
|
|
|
}
|