// runStart starts the cockroach node using --stores as the list of // storage devices ("stores") on this machine and --gossip as the list // of "well-known" hosts used to join this node to the cockroach // cluster via the gossip network. func runStart(cmd *cobra.Command, args []string) { info := util.GetBuildInfo() log.Infof("build Vers: %s", info.Vers) log.Infof("build Tag: %s", info.Tag) log.Infof("build Time: %s", info.Time) log.Infof("build Deps: %s", info.Deps) // Default user for servers. Context.User = security.NodeUser // First initialize the Context as it is used in other places. err := Context.Init("start") if err != nil { log.Errorf("failed to initialize context: %s", err) return } log.Info("starting cockroach cluster") stopper := util.NewStopper() stopper.AddWorker() s, err := server.NewServer(Context, stopper) if err != nil { log.Errorf("failed to start Cockroach server: %s", err) return } err = s.Start(false) if err != nil { log.Errorf("cockroach server exited with error: %s", err) return } signalCh := make(chan os.Signal, 1) signal.Notify(signalCh, os.Interrupt, os.Kill) // TODO(spencer): move this behind a build tag. signal.Notify(signalCh, syscall.SIGTERM) // Block until one of the signals above is received or the stopper // is stopped externally (for example, via the quit endpoint). select { case <-stopper.ShouldStop(): stopper.SetStopped() case <-signalCh: log.Infof("initiating graceful shutdown of server") stopper.SetStopped() go func() { s.Stop() }() } select { case <-signalCh: log.Warningf("second signal received, initiating hard shutdown") case <-time.After(time.Minute): log.Warningf("time limit reached, initiating hard shutdown") return case <-stopper.IsStopped(): log.Infof("server drained and shutdown completed") } log.Flush() }
// runStart starts the cockroach node using -stores as the list of // storage devices ("stores") on this machine and -gossip as the list // of "well-known" hosts used to join this node to the cockroach // cluster via the gossip network. func runStart(cmd *commander.Command, args []string) { info := util.GetBuildInfo() log.Infof("Build Vers: %s", info.Vers) log.Infof("Build Tag: %s", info.Tag) log.Infof("Build Time: %s", info.Time) log.Infof("Build Deps: %s", info.Deps) log.Info("Starting cockroach cluster") s, err := server.NewServer(Context) if err != nil { log.Errorf("Failed to start Cockroach server: %v", err) return } err = Context.Init() if err != nil { log.Errorf("Failed to initialize context: %v", err) return } err = s.Start(false) defer s.Stop() if err != nil { log.Errorf("Cockroach server exited with error: %v", err) return } c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, os.Kill) // Block until one of the signals above is received. <-c }
// runStart starts the cockroach node using --stores as the list of // storage devices ("stores") on this machine and --gossip as the list // of "well-known" hosts used to join this node to the cockroach // cluster via the gossip network. func runStart(cmd *cobra.Command, args []string) { info := util.GetBuildInfo() log.Infof("build Vers: %s", info.Vers) log.Infof("build Tag: %s", info.Tag) log.Infof("build Time: %s", info.Time) log.Infof("build Deps: %s", info.Deps) // Default user for servers. context.User = security.NodeUser if context.EphemeralSingleNode { context.Stores = "mem=1073741824" context.GossipBootstrap = server.SelfGossipAddr runInit(cmd, args) } else { if err := context.InitStores(); err != nil { log.Errorf("failed to initialize stores: %s", err) return } } if err := context.InitNode(); err != nil { log.Errorf("failed to initialize node: %s", err) return } log.Info("starting cockroach cluster") stopper := stop.NewStopper() s, err := server.NewServer(context, stopper) if err != nil { log.Errorf("failed to start Cockroach server: %s", err) return } if err := s.Start(false); err != nil { log.Errorf("cockroach server exited with error: %s", err) return } if context.EphemeralSingleNode { // TODO(tamird): pass this to BootstrapRange rather than doing it // at runtime. This was quicker, though. db, clientStopper := makeDBClient() if err := configutil.SetDefaultRangeReplicaNum(db, 1); err != nil { log.Errorf("failed to set default replica number: %s", err) } clientStopper.Stop() } signalCh := make(chan os.Signal, 1) signal.Notify(signalCh, os.Interrupt, os.Kill) // TODO(spencer): move this behind a build tag. signal.Notify(signalCh, syscall.SIGTERM) // Block until one of the signals above is received or the stopper // is stopped externally (for example, via the quit endpoint). select { case <-stopper.ShouldStop(): case <-signalCh: go s.Stop() } log.Info("initiating graceful shutdown of server") go func() { ticker := time.NewTicker(5 * time.Second) defer ticker.Stop() for { select { case <-ticker.C: if log.V(1) { log.Infof("running tasks:\n%s", stopper.RunningTasks()) } log.Infof("%d running tasks", stopper.NumTasks()) case <-stopper.ShouldStop(): return } } }() select { case <-signalCh: log.Warningf("second signal received, initiating hard shutdown") case <-time.After(time.Minute): log.Warningf("time limit reached, initiating hard shutdown") case <-stopper.IsStopped(): log.Infof("server drained and shutdown completed") } log.Flush() }