main.go 1.3 KB

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