cmd

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2017 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Version = "dev"
	Commit  = "none"
	Date    = "unknown"
)
View Source
var RootCmd = &cobra.Command{
	Use:   "sandglass",
	Short: "Launch the server",
	Long:  `Launch the server`,
	Run: func(cmd *cobra.Command, args []string) {
		conf := broker.Config{
			Name:                    viper.GetString("name"),
			BindAddr:                viper.GetString("bind_addr"),
			AdvertiseAddr:           viper.GetString("advertise_addr"),
			DBPath:                  viper.GetString("db_path"),
			GossipPort:              viper.GetString("gossip_port"),
			HTTPPort:                viper.GetString("http_port"),
			GRPCPort:                viper.GetString("grpc_port"),
			RaftPort:                viper.GetString("raft_port"),
			InitialPeers:            viper.GetStringSlice("initial_peers"),
			BootstrapRaft:           viper.GetBool("bootstrap_raft"),
			OffsetReplicationFactor: viper.GetInt("offset_replication_factor"),
		}

		if viper.GetBool("verbose") {
			lvl := logy.DEBUG
			conf.LoggingLevel = &lvl
		}

		b, err := broker.New(&conf)
		if err != nil {
			log.Fatal(errors.Cause(err))
		}

		if err := b.Bootstrap(); err != nil {
			log.Fatal(errors.Cause(err))
		}

		if err := b.Join(conf.InitialPeers...); err != nil {
			log.Fatal(err)
		}

		logger := log.New(os.Stdout, conf.Name, log.LstdFlags)
		server := server.New(b, net.JoinHostPort(conf.BindAddr, conf.GRPCPort), net.JoinHostPort(conf.BindAddr, conf.HTTPPort), logy.NewWithLogger(logger, logy.INFO))
		go func() {
			err := server.Start()
			if err != nil {
				log.Println(errors.Cause(err))
			}
		}()

		fmt.Println(warningColor("WARNING: This code is a very early release, it contains bugs and should not be used in production environments."))

		fmt.Println("")
		fmt.Println(infoColor("wait for it..."))
		err = b.WaitForIt()
		if err != nil {
			log.Fatal(err)
		}

		fmt.Println(sandglassColor(`
⏳  Sandglass started!
Beware of the sandstorm.
`))

		gracefully.Timeout = 10 * time.Second
		gracefully.Shutdown()
		b.Debug("graceful shutdown")
		ctx := context.Background()

		b.Debug("shutting down http server")
		if err := server.Shutdown(ctx); err != nil {
			log.Println(errors.Cause(err))
		}

		b.Debug("shutting down broker")
		if err := b.Stop(ctx); err != nil {
			log.Println(errors.Cause(err))
		}

		fmt.Println(sandglassColor("⌛️  sandglass stopped!"))
		os.Exit(0)
	},
}

RootCmd represents the base command when called without any subcommands

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.

Jump to

Keyboard shortcuts

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