github.com/slackhq/nebula@v1.9.0/cmd/nebula/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  	configPath := flag.String("config", "", "Path to either a file or directory to load configuration from")
    23  	configTest := flag.Bool("test", false, "Test the config and print the end result. Non zero exit indicates a faulty config")
    24  	printVersion := flag.Bool("version", false, "Print version")
    25  	printUsage := flag.Bool("help", false, "Print command line usage")
    26  
    27  	flag.Parse()
    28  
    29  	if *printVersion {
    30  		fmt.Printf("Version: %s\n", Build)
    31  		os.Exit(0)
    32  	}
    33  
    34  	if *printUsage {
    35  		flag.Usage()
    36  		os.Exit(0)
    37  	}
    38  
    39  	if *configPath == "" {
    40  		fmt.Println("-config flag must be set")
    41  		flag.Usage()
    42  		os.Exit(1)
    43  	}
    44  
    45  	l := logrus.New()
    46  	l.Out = os.Stdout
    47  
    48  	c := config.NewC(l)
    49  	err := c.Load(*configPath)
    50  	if err != nil {
    51  		fmt.Printf("failed to load config: %s", err)
    52  		os.Exit(1)
    53  	}
    54  
    55  	ctrl, err := nebula.Main(c, *configTest, Build, l, nil)
    56  	if err != nil {
    57  		util.LogWithContextIfNeeded("Failed to start", err, l)
    58  		os.Exit(1)
    59  	}
    60  
    61  	if !*configTest {
    62  		ctrl.Start()
    63  		notifyReady(l)
    64  		ctrl.ShutdownBlock()
    65  	}
    66  
    67  	os.Exit(0)
    68  }