Beispiel #1
0
func main() {
	rand.Seed(time.Now().UTC().UnixNano())
	sigQuitThreadDump()

	var logLevel string
	var version bool

	rootCmd := &cobra.Command{
		Use: "nerve config.yml",
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			if version {
				fmt.Println("Nerve")
				fmt.Println("Version :", Version)
				fmt.Println("Build Time :", BuildTime)
				os.Exit(0)
			}

			if logLevel != "" {
				level, err := logs.ParseLevel(logLevel)
				if err != nil {
					logs.WithField("value", logLevel).Fatal("Unknown log level")
				}
				logs.SetLevel(level)
			}
		},
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) != 1 {
				logs.Fatal("Nerve require a configuration file as argument")
			}
			nerve, err := LoadConfig(args[0])
			if err != nil {
				logs.WithE(err).Fatal("Cannot start, failed to load configuration")
			}

			if err := nerve.Init(Version, BuildTime, logLevel != ""); err != nil {
				logs.WithE(err).Fatal("Failed to init nerve")
			}

			startStatus := make(chan error)
			go nerve.Start(startStatus)
			if status := <-startStatus; status != nil {
				logs.WithE(status).Fatal("Failed to start nerve")
			}
			waitForSignal()
			nerve.Stop()
		},
	}

	rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "L", "", "Set log level")
	rootCmd.PersistentFlags().BoolVarP(&version, "version", "V", false, "Display version")

	if err := rootCmd.Execute(); err != nil {
		logs.WithE(err).Fatal("Failed to process args")
	}
}
Beispiel #2
0
func main() {
	rand.Seed(time.Now().UTC().UnixNano())
	sigQuitThreadDump()

	var logLevel string
	var version bool
	var oneshot bool

	rootCmd := &cobra.Command{
		Use: "synapse config.yml",
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			if version {
				fmt.Println("Synapse")
				fmt.Println("Version :", Version)
				fmt.Println("Build Time :", BuildTime)
				os.Exit(0)
			}

			if logLevel != "" {
				level, err := logs.ParseLevel(logLevel)
				if err != nil {
					logs.WithField("value", logLevel).Fatal("Unknown log level")
				}
				logs.SetLevel(level)
			}
		},
		Run: func(cmd *cobra.Command, args []string) {
			if len(args) != 1 {
				logs.Fatal("Synapse require a configuration file as argument")
			}
			synapse, err := LoadConfig(args[0])
			if err != nil {
				logs.WithE(err).Fatal("Cannot start, failed to load configuration")
			}

			if err := synapse.Init(Version, BuildTime, logLevel != ""); err != nil {
				logs.WithE(err).Fatal("Failed to init synapse")
			}

			if err := synapse.Start(oneshot); err != nil {
				logs.WithE(err).Fatal("Failed to start synapse")
			}
			waitForSignal()
			synapse.Stop()
		},
	}

	rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "L", "", "Set log level")
	rootCmd.PersistentFlags().BoolVarP(&version, "version", "V", false, "Display version")
	//rootCmd.PersistentFlags().BoolVarP(&oneshot, "oneshot", "O", false, "run watchers/router only once and exit")

	if err := rootCmd.Execute(); err != nil {
		logs.WithE(err).Fatal("Failed to process args")
	}
}
Beispiel #3
0
func main() {
	logs.GetDefaultLog().(*erlog.ErlogLogger).Appenders[0].(*erlog.ErlogWriterAppender).Out = os.Stdout
	logs.SetLevel(logs.TRACE)

	overrideEnvVarName := ""
	target := "/"
	var templateDir string

	processArgs(&overrideEnvVarName, &target, &templateDir)

	Run(overrideEnvVarName, target, templateDir)
}
Beispiel #4
0
func ProcessArgsAndReturnPodUUID() *types.UUID {
	flag.Parse()

	if cliDebugFlag {
		logs.SetLevel(logs.DEBUG)
	}
	if lvlStr := os.Getenv(common.EnvLogLevel); lvlStr != "" {
		lvl, err := logs.ParseLevel(lvlStr)
		if err != nil {
			fmt.Printf("Unknown log level : %s", lvlStr)
			os.Exit(1)
		}
		logs.SetLevel(lvl)
	}

	arg := flag.Arg(0)
	uuid, err := types.NewUUID(arg)
	if err != nil {
		logs.WithE(err).WithField("content", arg).Fatal("UUID is missing or malformed")
	}
	return uuid
}
Beispiel #5
0
func Execute() {
	var version bool
	var homePath string
	var targetRootPath string
	var logLevel string

	var rootCmd = &cobra.Command{
		Use: "dgr",
		Run: func(cmd *cobra.Command, args []string) {
			cmd.Help()
			os.Exit(1)
		},
		PersistentPreRun: func(cmd *cobra.Command, args []string) {
			if version {
				displayVersionAndExit()
			}

			level, err := logs.ParseLevel(logLevel)
			if err != nil {
				fmt.Printf("Unknown log level : %s", logLevel)
				os.Exit(1)
			}
			logs.SetLevel(level)

			Home = NewHome(homePath)

			if targetRootPath != "" {
				Home.Config.TargetWorkDir = targetRootPath
			}
		},
	}
	//rootCmd.PersistentFlags().BoolVarP(&Args.Clean, "clean", "c", false, "Clean before doing anything")
	rootCmd.PersistentFlags().StringVarP(&targetRootPath, "targets-root-path", "p", "", "Set targets root path")
	rootCmd.PersistentFlags().StringVarP(&logLevel, "loglevel", "L", "info", "Set log level")
	rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", "info", "Set log level")
	rootCmd.PersistentFlags().StringVarP(&homePath, "home-path", "H", DefaultHomeFolder(""), "Set home folder")
	rootCmd.PersistentFlags().StringVarP(&workPath, "work-path", "W", ".", "Set the work path")
	rootCmd.PersistentFlags().BoolVarP(&version, "version", "V", false, "Display dgr version")
	rootCmd.PersistentFlags().Var(&Args.SetEnv, "set-env", "Env passed to builder scripts")
	rootCmd.PersistentFlags().BoolVar(&Args.StoreOnly, "store-only", false, "Tell rkt to use the store only")
	rootCmd.PersistentFlags().BoolVar(&Args.NoStore, "no-store", false, "Tell rkt to not use store")
	rootCmd.PersistentFlags().BoolVarP(&Args.SerialBuild, "serial", "S", false, "Run build in serial (disable parallel builds)")

	rootCmd.AddCommand(buildCmd, cleanCmd, pushCmd, installCmd, testCmd, versionCmd, initCmd, graphCmd, tryCmd /*signCmd,*/, aciVersion)

	readEnvironment()
	rootCmd.Execute()

	logs.Debug("Victory !")
}
Beispiel #6
0
func Execute() {
	checkRktVersion()

	var logLevel string
	var rootCmd = &cobra.Command{
		Use: "cnt",
	}
	var homePath string
	var targetRootPath string
	rootCmd.PersistentFlags().BoolVarP(&buildArgs.Clean, "clean", "c", false, "Clean before doing anything")
	rootCmd.PersistentFlags().StringVarP(&targetRootPath, "targets-root-path", "p", "", "Set targets root path")
	rootCmd.PersistentFlags().StringVarP(&logLevel, "loglevel", "L", "info", "Set log level")
	rootCmd.PersistentFlags().StringVarP(&homePath, "home-path", "H", cnt.DefaultHomeFolder(), "Set home folder")
	rootCmd.PersistentFlags().StringVarP(&workPath, "work-path", "W", ".", "Set the work path")

	rootCmd.AddCommand(buildCmd, cleanCmd, pushCmd, installCmd, testCmd, versionCmd, initCmd /*updateCmd,*/, graphCmd, aciVersion)
	rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {

		// logs

		level, err := logs.ParseLevel(logLevel)
		if err != nil {
			fmt.Printf("Unknown log level : %s", logLevel)
			os.Exit(1)
		}
		logs.SetLevel(level)

		cnt.Home = cnt.NewHome(homePath)

		// targetRootPath
		if targetRootPath != "" {
			cnt.Home.Config.TargetWorkDir = targetRootPath
		}

	}

	//
	//	if config.GetConfig().TargetWorkDir != "" {
	//		buildArgs.TargetsRootPath = config.GetConfig().TargetWorkDir
	//	}

	rootCmd.Execute()

	logs.Debug("Victory !")
}
Beispiel #7
0
func main() {
	logs.GetDefaultLog().(*erlog.ErlogLogger).Appenders[0].(*erlog.ErlogWriterAppender).Out = os.Stdout

	overrideEnvVarName := ""
	target := "/"
	var templateDir string
	logLvl := "INFO"

	processArgs(&overrideEnvVarName, &target, &templateDir, &logLvl)

	lvl, err := logs.ParseLevel(logLvl)
	if err != nil {
		fmt.Println("Wrong log level : " + logLvl)
		os.Exit(1)
	}
	logs.SetLevel(lvl)

	Run(overrideEnvVarName, target, templateDir)
}
Beispiel #8
0
func (n *Nerve) Init(version string, buildTime string, logLevelIsSet bool) error {
	n.nerveVersion = version
	n.nerveBuildTime = buildTime
	if n.ApiPort == 0 {
		n.ApiPort = 3454
	}

	if !logLevelIsSet && n.LogLevel != nil {
		logs.SetLevel(*n.LogLevel)
	}

	n.checkerFailureCount = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "nerve",
			Name:      "checker_failure_total",
			Help:      "Counter of failed check",
		}, []string{"name", "ip", "port", "type"})

	n.execFailureCount = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "nerve",
			Name:      "exec_failure_total",
			Help:      "Counter of failed exec",
		}, []string{"name", "ip", "port", "type"})

	n.reporterFailureCount = prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "nerve",
			Name:      "reporter_failure_total",
			Help:      "Counter of report failure",
		}, []string{"name", "ip", "port", "type"})

	n.availableGauge = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: "nerve",
			Name:      "service_available",
			Help:      "service available status",
		}, []string{"name", "ip", "port"})

	if err := prometheus.Register(n.execFailureCount); err != nil {
		return errs.WithEF(err, n.fields, "Failed to register prometheus exec_failure_total")
	}
	if err := prometheus.Register(n.checkerFailureCount); err != nil {
		return errs.WithEF(err, n.fields, "Failed to register prometheus check_failure_total")
	}
	if err := prometheus.Register(n.reporterFailureCount); err != nil {
		return errs.WithEF(err, n.fields, "Failed to register prometheus reporterFailureCount")
	}
	if err := prometheus.Register(n.availableGauge); err != nil {
		return errs.WithEF(err, n.fields, "Failed to register prometheus service_available")
	}

	n.serviceStopper = make(chan struct{})
	for _, service := range n.Services {
		if err := service.Init(n); err != nil {
			return errs.WithEF(err, data.WithField("service", service.Name), "Failed to init service")
		}
	}

	m := make(map[string]*Service)
	for i, service := range n.Services {
		m[service.Name] = service
		if len(m) != i+1 {
			return errs.WithF(n.fields.WithField("name", service.Name), "Duplicate service name")
		}
	}

	return nil
}
Beispiel #9
0
func (s *Synapse) Init(version string, buildTime string, logLevelIsSet bool) error {
	s.synapseBuildTime = buildTime
	s.synapseVersion = version

	if s.ApiPort == 0 {
		s.ApiPort = 3455
	}

	if !logLevelIsSet && s.LogLevel != nil {
		logs.SetLevel(*s.LogLevel)
	}

	s.routerUpdateFailures = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: "synapse",
			Name:      "router_update_failure",
			Help:      "router update failures",
		}, []string{"type"})

	s.serviceAvailableCount = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: "synapse",
			Name:      "service_available_count",
			Help:      "service available status",
		}, []string{"service"})

	s.serviceUnavailableCount = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: "synapse",
			Name:      "service_unavailable_count",
			Help:      "service unavailable status",
		}, []string{"service"})

	s.watcherFailures = prometheus.NewGaugeVec(
		prometheus.GaugeOpts{
			Namespace: "synapse",
			Name:      "watcher_failure",
			Help:      "watcher failure",
		}, []string{"service", "type"})

	if err := prometheus.Register(s.watcherFailures); err != nil {
		return errs.WithEF(err, s.fields, "Failed to register prometheus watcher_failure")
	}

	if err := prometheus.Register(s.serviceAvailableCount); err != nil {
		return errs.WithEF(err, s.fields, "Failed to register prometheus service_available_count")
	}

	if err := prometheus.Register(s.serviceUnavailableCount); err != nil {
		return errs.WithEF(err, s.fields, "Failed to register prometheus service_unavailable_count")
	}

	if err := prometheus.Register(s.routerUpdateFailures); err != nil {
		return errs.WithEF(err, s.fields, "Failed to register prometheus router_update_failure")
	}

	for _, data := range s.Routers {
		router, err := RouterFromJson(data, s)
		if err != nil {
			return errs.WithE(err, "Failed to init router")
		}
		s.typedRouters = append(s.typedRouters, router)
	}

	return nil
}