2017-10-01 23:30:48 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"syscall"
|
|
|
|
|
2017-10-02 14:38:52 +02:00
|
|
|
"dev.sum7.eu/genofire/yaja/model/config"
|
|
|
|
|
2017-10-01 23:30:48 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2017-10-02 14:38:52 +02:00
|
|
|
var configPath string
|
|
|
|
|
2017-10-01 23:30:48 +02:00
|
|
|
// serveCmd represents the serve command
|
|
|
|
var serveCmd = &cobra.Command{
|
|
|
|
Use: "serve",
|
|
|
|
Short: "Runs the yaja server",
|
2017-10-02 14:38:52 +02:00
|
|
|
Example: "yaja serve -c /etc/yaja.conf",
|
2017-10-01 23:30:48 +02:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2017-10-02 14:38:52 +02:00
|
|
|
_, err := config.ReadConfigFile(configPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("unable to load config file:", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Infoln("yaja started ")
|
2017-10-01 23:30:48 +02:00
|
|
|
|
|
|
|
// Wait for INT/TERM
|
|
|
|
sigs := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
|
|
|
sig := <-sigs
|
|
|
|
log.Infoln("received", sig)
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
RootCmd.AddCommand(serveCmd)
|
2017-10-02 14:38:52 +02:00
|
|
|
serveCmd.Flags().StringVarP(&configPath, "config", "c", "yaja.conf", "Path to configuration file")
|
2017-10-01 23:30:48 +02:00
|
|
|
}
|