commands

package
v3.14.2 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2021 License: Apache-2.0 Imports: 67 Imported by: 0

Documentation

Overview

Package commands implements the commands for the ttn-lw-stack binary.

Index

Constants

This section is empty.

Variables

DefaultConfig contains the default config for the ttn-lw-stack binary.

View Source
var (

	// Root command is the entrypoint of the program
	Root = &cobra.Command{
		Use:           name,
		SilenceErrors: true,
		SilenceUsage:  true,
		Short:         "The Things Stack for LoRaWAN",
		PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

			err := mgr.ReadInConfig()
			if err != nil {
				return err
			}

			if err = mgr.Unmarshal(config); err != nil {
				return err
			}

			if err := shared.InitializeFallbacks(&config.ServiceBase); err != nil {
				return err
			}

			logger, err = shared.InitializeLogger(&config.Log)
			if err != nil {
				return err
			}

			logger.Use(logobservability.New())

			if config.Sentry.DSN != "" {
				opts := sentry.ClientOptions{
					Dsn:         config.Sentry.DSN,
					Release:     pkgversion.String(),
					Environment: config.Sentry.Environment,
				}
				if hostname, err := os.Hostname(); err == nil {
					opts.ServerName = hostname
				}
				err = sentry.Init(opts)
				if err != nil {
					return err
				}
				logger.Use(logsentry.New())
			}

			ctx = log.NewContext(ctx, logger)

			versionUpdate = make(chan pkgversion.Update)
			if config.SkipVersionCheck {
				close(versionUpdate)
			} else {
				go func(ctx context.Context) {
					defer close(versionUpdate)
					update, err := pkgversion.CheckUpdate(ctx)
					if err != nil {
						log.FromContext(ctx).WithError(err).Warn("Failed to check version update")
					} else if update != nil {
						versionUpdate <- *update
					} else {
						log.FromContext(ctx).Debug("No new version available")
					}
				}(ctx)
			}

			return nil
		},
		PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
			select {
			case <-ctx.Done():
			case <-time.After(versionCheckTimeout):
				logger.Warn("Version check timed out")
			case versionUpdate, ok := <-versionUpdate:
				if ok {
					pkgversion.LogUpdate(ctx, &versionUpdate)
				}
			}
			return nil
		},
	}
)

Functions

func NewComponentDeviceRegistryRedis added in v3.9.3

func NewComponentDeviceRegistryRedis(conf Config, name string) *redis.Client

func NewNetworkServerApplicationUplinkQueueRedis added in v3.9.3

func NewNetworkServerApplicationUplinkQueueRedis(conf Config) *redis.Client

func NewNetworkServerDeviceRegistryRedis added in v3.9.3

func NewNetworkServerDeviceRegistryRedis(conf Config) *redis.Client

func NewNetworkServerDownlinkTaskRedis added in v3.9.3

func NewNetworkServerDownlinkTaskRedis(conf Config) *redis.Client

Types

type Config

type Config struct {
	conf.ServiceBase `name:",squash"`
	IS               identityserver.Config             `name:"is"`
	GS               gatewayserver.Config              `name:"gs"`
	NS               networkserver.Config              `name:"ns"`
	AS               applicationserver.Config          `name:"as"`
	JS               joinserver.Config                 `name:"js"`
	Console          console.Config                    `name:"console"`
	GCS              gatewayconfigurationserver.Config `name:"gcs"`
	DTC              devicetemplateconverter.Config    `name:"dtc"`
	QRG              qrcodegenerator.Config            `name:"qrg"`
	PBA              packetbrokeragent.Config          `name:"pba"`
	DR               devicerepository.Config           `name:"dr"`
	OutputFormat     string                            `name:"output-format" yaml:"output-format" description:"Output format"`
}

Config for the ttn-lw-stack binary.

Jump to

Keyboard shortcuts

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