github.com/vlifesystems/rulehunter@v0.0.0-20180501090014-673078aa4a83/cmd/serve.go (about) 1 // Copyright (C) 2016-2018 vLife Systems Ltd <http://vlifesystems.com> 2 // Licensed under an MIT licence. Please see LICENSE.md for details. 3 4 package cmd 5 6 import ( 7 "github.com/spf13/cobra" 8 "github.com/vlifesystems/rulehunter/logger" 9 "github.com/vlifesystems/rulehunter/quitter" 10 ) 11 12 var ServeCmd = &cobra.Command{ 13 Use: "serve", 14 Short: "Run Rulehunter as a server", 15 Long: `Rulehunter will run as a server continually monitoring an 'experiments' 16 directory and processing its contents.`, 17 RunE: func(cmd *cobra.Command, args []string) error { 18 l := logger.NewSvcLogger() 19 q := quitter.New() 20 defer q.Quit() 21 return runServe(l, q, flagConfigFilename) 22 }, 23 } 24 25 func runServe( 26 l logger.Logger, 27 q *quitter.Quitter, 28 configFilename string, 29 ) error { 30 s, err := InitSetup(l, q, configFilename) 31 if err != nil { 32 return err 33 } 34 go httpServer(s.cfg.HTTPPort, s.cfg.WWWDir, q, l) 35 if err := s.svc.Run(); err != nil { 36 return err 37 } 38 return nil 39 }