cmd

package
v2.5.4+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2017 License: MIT Imports: 50 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RedisConnectRetries = 10

RedisConnectRetries indicates how many times the Redis connection should be retried

View Source
var RedisConnectRetryDelay = 1 * time.Second

RedisConnectRetryDelay indicates the time between Redis connection retries

View Source
var RootCmd = &cobra.Command{
	Use:   "ttn",
	Short: "The Things Network's backend servers",
	Long:  `ttn launches The Things Network's backend servers`,
	PersistentPreRun: func(cmd *cobra.Command, args []string) {
		var logLevel = log.InfoLevel
		if viper.GetBool("debug") {
			logLevel = log.DebugLevel
		}

		var logHandlers []log.Handler

		if !viper.GetBool("no-cli-logs") {
			logHandlers = append(logHandlers, levelHandler.New(cliHandler.New(os.Stdout), logLevel))
		}

		if logFileLocation := viper.GetString("log-file"); logFileLocation != "" {
			absLogFileLocation, err := filepath.Abs(logFileLocation)
			if err != nil {
				panic(err)
			}
			logFile, err = os.OpenFile(absLogFileLocation, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0644)
			if err != nil {
				panic(err)
			}
			if err == nil {
				logHandlers = append(logHandlers, levelHandler.New(jsonHandler.New(logFile), logLevel))
			}
		}

		if esServer := viper.GetString("elasticsearch"); esServer != "" {
			esClient := elastic.New(esServer)
			esClient.HTTPClient = &http.Client{
				Timeout: 5 * time.Second,
			}
			logHandlers = append(logHandlers, levelHandler.New(esHandler.New(&esHandler.Config{
				Client:     esClient,
				Prefix:     cmd.Name(),
				BufferSize: 10,
			}), logLevel))
		}

		ctx = apex.Wrap(&log.Logger{
			Handler: multiHandler.New(logHandlers...),
		})
		ttnlog.Set(ctx)
		grpclog.SetLogger(grpc.Wrap(ttnlog.Get()))

		ctx.WithFields(ttnlog.Fields{
			"ComponentID":              viper.GetString("id"),
			"Description":              viper.GetString("description"),
			"Discovery Server Address": viper.GetString("discovery-address"),
			"Auth Servers":             viper.GetStringMapString("auth-servers"),
			"Monitors":                 viper.GetStringMapString("monitor-servers"),
		}).Info("Initializing The Things Network")
	},
	PersistentPostRun: func(cmd *cobra.Command, args []string) {
		if logFile != nil {
			logFile.Close()
		}
	},
}

RootCmd is executed when ttn is executed without a subcommand

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL