2019-06-13 19:25:32 +00:00
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2019-06-15 13:45:35 +00:00
|
|
|
"log"
|
|
|
|
|
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-06-15 14:42:54 +00:00
|
|
|
var compression bool
|
2019-06-15 12:25:45 +00:00
|
|
|
var configPath string
|
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-06-15 13:45:35 +00:00
|
|
|
cnf, err := config.Read(configPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-06-15 14:42:54 +00:00
|
|
|
err = daemon.Start(cnf, compression)
|
2019-06-15 13:45:35 +00:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-06-13 19:25:32 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2019-06-15 12:25:45 +00:00
|
|
|
func InitCmd(cmd *cobra.Command, cnfPath string) {
|
|
|
|
configPath = cnfPath
|
2019-06-13 19:25:32 +00:00
|
|
|
cmd.AddCommand(daemonCmd)
|
2019-06-15 14:42:54 +00:00
|
|
|
daemonCmd.Flags().BoolVarP(&compression, "compression", "c", true, "Compress measured values")
|
2019-06-13 19:25:32 +00:00
|
|
|
|
|
|
|
}
|