github.com/slackhq/nebula@v1.9.0/cmd/nebula-service/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "os" 7 8 "github.com/sirupsen/logrus" 9 "github.com/slackhq/nebula" 10 "github.com/slackhq/nebula/config" 11 "github.com/slackhq/nebula/util" 12 ) 13 14 // A version string that can be set with 15 // 16 // -ldflags "-X main.Build=SOMEVERSION" 17 // 18 // at compile-time. 19 var Build string 20 21 func main() { 22 serviceFlag := flag.String("service", "", "Control the system service.") 23 configPath := flag.String("config", "", "Path to either a file or directory to load configuration from") 24 configTest := flag.Bool("test", false, "Test the config and print the end result. Non zero exit indicates a faulty config") 25 printVersion := flag.Bool("version", false, "Print version") 26 printUsage := flag.Bool("help", false, "Print command line usage") 27 28 flag.Parse() 29 30 if *printVersion { 31 fmt.Printf("Version: %s\n", Build) 32 os.Exit(0) 33 } 34 35 if *printUsage { 36 flag.Usage() 37 os.Exit(0) 38 } 39 40 if *serviceFlag != "" { 41 doService(configPath, configTest, Build, serviceFlag) 42 os.Exit(1) 43 } 44 45 if *configPath == "" { 46 fmt.Println("-config flag must be set") 47 flag.Usage() 48 os.Exit(1) 49 } 50 51 l := logrus.New() 52 l.Out = os.Stdout 53 54 c := config.NewC(l) 55 err := c.Load(*configPath) 56 if err != nil { 57 fmt.Printf("failed to load config: %s", err) 58 os.Exit(1) 59 } 60 61 ctrl, err := nebula.Main(c, *configTest, Build, l, nil) 62 if err != nil { 63 util.LogWithContextIfNeeded("Failed to start", err, l) 64 os.Exit(1) 65 } 66 67 if !*configTest { 68 ctrl.Start() 69 ctrl.ShutdownBlock() 70 } 71 72 os.Exit(0) 73 }