2019-11-19 19:55:02 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
2020-07-01 00:53:30 +02:00
|
|
|
"os"
|
|
|
|
|
2020-06-30 20:48:58 +02:00
|
|
|
"github.com/sirupsen/logrus"
|
2019-11-19 19:55:02 +01:00
|
|
|
"github.com/slackhq/nebula"
|
2021-11-04 02:54:04 +01:00
|
|
|
"github.com/slackhq/nebula/config"
|
2019-11-19 19:55:02 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// A version string that can be set with
|
|
|
|
//
|
|
|
|
// -ldflags "-X main.Build=SOMEVERSION"
|
|
|
|
//
|
|
|
|
// at compile-time.
|
|
|
|
var Build string
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
serviceFlag := flag.String("service", "", "Control the system service.")
|
|
|
|
configPath := flag.String("config", "", "Path to either a file or directory to load configuration from")
|
|
|
|
configTest := flag.Bool("test", false, "Test the config and print the end result. Non zero exit indicates a faulty config")
|
|
|
|
printVersion := flag.Bool("version", false, "Print version")
|
|
|
|
printUsage := flag.Bool("help", false, "Print command line usage")
|
|
|
|
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if *printVersion {
|
2019-11-28 17:25:34 +01:00
|
|
|
fmt.Printf("Version: %s\n", Build)
|
2019-11-19 19:55:02 +01:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *printUsage {
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *serviceFlag != "" {
|
|
|
|
doService(configPath, configTest, Build, serviceFlag)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
if *configPath == "" {
|
|
|
|
fmt.Println("-config flag must be set")
|
|
|
|
flag.Usage()
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-03-26 15:46:30 +01:00
|
|
|
l := logrus.New()
|
|
|
|
l.Out = os.Stdout
|
|
|
|
|
2021-11-04 02:54:04 +01:00
|
|
|
c := config.NewC(l)
|
|
|
|
err := c.Load(*configPath)
|
2020-06-30 20:48:58 +02:00
|
|
|
if err != nil {
|
|
|
|
fmt.Printf("failed to load config: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-11-04 02:54:04 +01:00
|
|
|
ctrl, err := nebula.Main(c, *configTest, Build, l, nil)
|
2020-06-30 20:48:58 +02:00
|
|
|
|
|
|
|
switch v := err.(type) {
|
|
|
|
case nebula.ContextualError:
|
|
|
|
v.Log(l)
|
|
|
|
os.Exit(1)
|
|
|
|
case error:
|
|
|
|
l.WithError(err).Error("Failed to start")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2020-09-18 16:20:09 +02:00
|
|
|
if !*configTest {
|
2021-11-04 02:54:04 +01:00
|
|
|
ctrl.Start()
|
|
|
|
ctrl.ShutdownBlock()
|
2020-09-18 16:20:09 +02:00
|
|
|
}
|
|
|
|
|
2020-06-30 20:48:58 +02:00
|
|
|
os.Exit(0)
|
2019-11-19 19:55:02 +01:00
|
|
|
}
|