// startGoRoutine starts the given function as a go routine if and only if
// the server was not shutdown at that time. This is required because
// we cannot increment the wait group after the shutdown process has started.
423301
func (s *StanServer) startGoRoutine(f func()) {
	s.mu.Lock()
	if !s.shutdown {
		s.wg.Add(1)
		go f()
	}
	s.mu.Unlock()
}
147625
func (server *Server) Start() {
	go func() {
		server.setUpRoutes()
		log.Printf("STARTING REDISMQ SERVER ON PORT %s", server.port)
		err := http.ListenAndServe(":"+server.port, nil)
		if err != nil {
			log.Fatalf("REDISMQ SERVER SHUTTING DOWN [%s]\n\n", err.Error())
		}
	}()
}
277785
func (awsManager *AwsManager) Start(gs gracefulshutdown.GSInterface) error {
	awsManager.gs = gs

	if awsManager.config.Region == "" {
		availabilityZone, err := awsManager.api.GetMetadata("placement/availability-zone")
		if err != nil {
			return err
		}
		awsManager.config.Region = availabilityZone[:len(availabilityZone)-1]
	}

	if awsManager.config.InstanceId == "" {
		instanceId, err := awsManager.api.GetMetadata("instance-id")
		if err != nil {
			return err
		}
		awsManager.config.InstanceId = instanceId
	}

	if err := awsManager.api.Init(awsManager.config); err != nil {
		return err
	}

	awsManager.gs.AddShutdownCallback(awsManager)

	if awsManager.config.SqsQueueName != "" {
		go awsManager.listenSQS()
	}

	if awsManager.config.Port != 0 {
		go awsManager.listenHTTP()
	}

	return nil
}
1274377
func (s *Server) Start() {

	http.HandleFunc("/", index)
	http.Handle("/stats/app", &statsHandler{
		stats:  s.Stats,
		logger: s.Logger,
	})
	http.HandleFunc("/stats/runtime", stats_api.Handler)

	port := DefaultPort
	if p := os.Getenv(EnvPort); p != "" {
		port = p
	}

	s.Logger.Printf("[INFO] Start server listening on :%s", port)
	if err := http.ListenAndServe(":"+port, nil); err != nil {
		s.Logger.Printf("[ERROR] Failed to start varz-server: %s", err)
	}
}
1151864
func (l *logdogServer) Start(ctx context.Context) error {
	if l.serv != nil {
		return errors.Reason("already started").Err()
	}

	disableGRPCLogging(ctx)

	serv, err := newLogDogStreamServerForPlatform(withNonCancel(ctx), l.WorkDir)
	if err != nil {
		return errors.Annotate(err, "failed to create stream server").Err()
	}

	if err := serv.Listen(); err != nil {
		return errors.Annotate(err, "failed to listen on stream server").Err()
	}
	logging.Debugf(ctx, "Generated stream server at: %s", serv.Address())
	defer func() {
		if err != nil {
			serv.Close()
		}
	}()

	// Create a butler output.
	var output output.Output
	if l.LocalFile != "" {
		// Debug: Use a file output.
		outCfg := file.Options{Path: l.LocalFile}
		output = outCfg.New(ctx)
	} else {
		outCfg := out.Config{
			Auth:           l.Authenticator,
			Host:           l.CoordinatorHost,
			Project:        l.Project,
			Prefix:         l.Prefix,
			SourceInfo:     []string{"luci_runner"},
			RPCTimeout:     defaultRPCTimeout,
			PublishContext: withNonCancel(ctx),
		}
		output, err = outCfg.Register(ctx)
		if err != nil {
			return errors.Annotate(err, "failed to create output instance").Err()
		}
	}
	defer func() {
		if err != nil {
			output.Close()
		}
	}()

	// Create a Butler.
	cfg := butler.Config{
		Output:                     output,
		Project:                    l.Project,
		Prefix:                     l.Prefix,
		BufferLogs:                 true,
		MaxBufferAge:               butler.DefaultMaxBufferAge,
		GlobalTags:                 l.GlobalTags,
		StreamRegistrationCallback: l.StreamRegistrationCallback,
		TeeStdout:                  os.Stdout,
		TeeStderr:                  os.Stderr,
	}
	butler, err := butler.New(ctx, cfg)

	if err != nil {
		return err
	}

	butler.AddStreamServer(serv)

	l.serv = serv
	l.output = output
	l.butler = butler
	return nil
}
800612
func (sv *Service) Start(t *testing.T) <-chan error {
	srv, err := embed.StartEtcd(sv.cfg)
	if err != nil {
		t.Fatal(err)
	}
	select {
	case <-srv.Server.ReadyNotify():
		err = nil
	case err = <-srv.Err():
	case <-srv.Server.StopNotify():
		err = fmt.Errorf("received from etcdserver.Server.StopNotify")
	}
	if err != nil {
		t.Fatal(err)
	}
	sv.etcd = srv

	// issue linearized read to ensure leader election
	cli := v3client.New(srv.Server)
	_, err = cli.Get(context.Background(), "foo")

	go func() {
		defer close(sv.httpErrc)
		if err := sv.httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			sv.httpErrc <- err
			return
		}
		sv.httpErrc <- nil
	}()
	return sv.httpErrc
}
411700
func (m *Command) Start() (err error) {
	defer close(m.Started)

	// Seed random number generator
	rand.Seed(time.Now().UTC().UnixNano())

	// SetupServer
	err = m.SetupServer()
	if err != nil {
		return errors.Wrap(err, "setting up server")
	}

	// SetupNetworking
	err = m.setupNetworking()
	if err != nil {
		return errors.Wrap(err, "setting up networking")
	}
	go func() {
		err := m.Handler.Serve()
		if err != nil {
			m.logger.Printf("handler serve error: %v", err)
		}
	}()

	// Initialize server.
	if err = m.Server.Open(); err != nil {
		return errors.Wrap(err, "opening server")
	}

	m.logger.Printf("listening as %s\n", m.listenURI)

	return nil
}
185043
func (gs *Server) StartRoutine() {
	gs.wg.Add(1)
	atomic.AddInt32(&gs.routinesCount, 1)
}
77764
func (p *Parser) Start() (err error) {
	var msg *outerMessage

	defer p.afterStop()

	defer func() {
		if x, ok := recover().(error); ok {
			err = x
		}
	}()

	// Loop through all outer messages until we're signaled to stop. Stopping
	// happens when either the OnCDemoStop message is encountered or
	// parser.Stop() is called programatically.
	for !p.isStopping {
		if p.stopAtTick > 0 && p.Tick > p.stopAtTick {
			return
		}

		msg, err = p.readOuterMessage()
		if err != nil {
			if err == io.EOF {
				err = nil
			}
			return
		}

		p.Tick = msg.tick

		if err = p.Callbacks.callByDemoType(msg.typeId, msg.data); err != nil {
			return
		}
	}

	return
}
1235282
func Start(plgn Plugin) {
	gob.Register(plgn)
	RegisterPlugin(plgn.GetMeta().Name, plgn)

	if len(os.Args) == 2 && os.Args[1] == PluginMeta {
		b, _ := json.Marshal(plgn.GetMeta())
		UIOutput(string(b))

	} else {

		plugin.Serve(&plugin.ServeConfig{
			HandshakeConfig: handshakeConfig,
			Plugins:         GetPlugins(),
		})
	}
}
163947
func Start(options ...func(*Profile)) interface {
	Stop()
} {
	if !atomic.CompareAndSwapUint32(&started, 0, 1) {
		log.Fatal("profile: Start() already called")
	}

	var prof Profile
	for _, option := range options {
		option(&prof)
	}

	path, err := func() (string, error) {
		if p := prof.path; p != "" {
			return p, os.MkdirAll(p, 0777)
		}
		return ioutil.TempDir("", "profile")
	}()

	if err != nil {
		log.Fatalf("profile: could not create initial output directory: %v", err)
	}

	logf := func(format string, args ...interface{}) {
		if !prof.quiet {
			log.Printf(format, args...)
		}
	}

	switch prof.mode {
	case cpuMode:
		fn := filepath.Join(path, "cpu.pprof")
		f, err := os.Create(fn)
		if err != nil {
			log.Fatalf("profile: could not create cpu profile %q: %v", fn, err)
		}
		logf("profile: cpu profiling enabled, %s", fn)
		pprof.StartCPUProfile(f)
		prof.closer = func() {
			pprof.StopCPUProfile()
			f.Close()
			logf("profile: cpu profiling disabled, %s", fn)
		}

	case memMode:
		fn := filepath.Join(path, "mem.pprof")
		f, err := os.Create(fn)
		if err != nil {
			log.Fatalf("profile: could not create memory profile %q: %v", fn, err)
		}
		old := runtime.MemProfileRate
		runtime.MemProfileRate = prof.memProfileRate
		logf("profile: memory profiling enabled (rate %d), %s", runtime.MemProfileRate, fn)
		prof.closer = func() {
			pprof.Lookup("heap").WriteTo(f, 0)
			f.Close()
			runtime.MemProfileRate = old
			logf("profile: memory profiling disabled, %s", fn)
		}

	case mutexMode:
		fn := filepath.Join(path, "mutex.pprof")
		f, err := os.Create(fn)
		if err != nil {
			log.Fatalf("profile: could not create mutex profile %q: %v", fn, err)
		}
		enableMutexProfile()
		logf("profile: mutex profiling enabled, %s", fn)
		prof.closer = func() {
			if mp := pprof.Lookup("mutex"); mp != nil {
				mp.WriteTo(f, 0)
			}
			f.Close()
			disableMutexProfile()
			logf("profile: mutex profiling disabled, %s", fn)
		}

	case blockMode:
		fn := filepath.Join(path, "block.pprof")
		f, err := os.Create(fn)
		if err != nil {
			log.Fatalf("profile: could not create block profile %q: %v", fn, err)
		}
		runtime.SetBlockProfileRate(1)
		logf("profile: block profiling enabled, %s", fn)
		prof.closer = func() {
			pprof.Lookup("block").WriteTo(f, 0)
			f.Close()
			runtime.SetBlockProfileRate(0)
			logf("profile: block profiling disabled, %s", fn)
		}

	case threadCreateMode:
		fn := filepath.Join(path, "threadcreation.pprof")
		f, err := os.Create(fn)
		if err != nil {
			log.Fatalf("profile: could not create thread creation profile %q: %v", fn, err)
		}
		logf("profile: thread creation profiling enabled, %s", fn)
		prof.closer = func() {
			if mp := pprof.Lookup("threadcreate"); mp != nil {
				mp.WriteTo(f, 0)
			}
			f.Close()
			logf("profile: thread creation profiling disabled, %s", fn)
		}

	case traceMode:
		fn := filepath.Join(path, "trace.out")
		f, err := os.Create(fn)
		if err != nil {
			log.Fatalf("profile: could not create trace output file %q: %v", fn, err)
		}
		if err := startTrace(f); err != nil {
			log.Fatalf("profile: could not start trace: %v", err)
		}
		logf("profile: trace enabled, %s", fn)
		prof.closer = func() {
			stopTrace()
			logf("profile: trace disabled, %s", fn)
		}
	}

	if !prof.noShutdownHook {
		go func() {
			c := make(chan os.Signal, 1)
			signal.Notify(c, os.Interrupt)
			<-c

			log.Println("profile: caught interrupt, stopping profiles")
			prof.Stop()

			os.Exit(0)
		}()
	}

	return &prof
}
234005
func (s *NeutrinoClient) Start() error {
	s.CS.Start()
	s.clientMtx.Lock()
	defer s.clientMtx.Unlock()
	if !s.started {
		s.enqueueNotification = make(chan interface{})
		s.dequeueNotification = make(chan interface{})
		s.currentBlock = make(chan *waddrmgr.BlockStamp)
		s.quit = make(chan struct{})
		s.started = true
		s.wg.Add(1)
		go func() {
			select {
			case s.enqueueNotification <- ClientConnected{}:
			case <-s.quit:
			}
		}()
		go s.notificationHandler()
	}
	return nil
}
1015938
func (prg *Program) Start(srv service.Service) error {
	os.Exit(0)
	return nil
}
14737
func (s *Server) Start(ctx context.Context) {
	go func() {
		defer s.Close()
		<-ctx.Done()
		logger := log.FromContext(ctx)
		logger.Info("I have to go...")
		logger.Info("Stopping server gracefully")
		s.Stop()
	}()

	s.startTCPServers()
	s.routinesPool.Go(func(stop chan bool) {
		s.listenProviders(stop)
	})
	s.routinesPool.Go(func(stop chan bool) {
		s.listenConfigurations(stop)
	})
	s.startProvider()
	s.routinesPool.Go(func(stop chan bool) {
		s.listenSignals(stop)
	})
}
165027
func (cmd *CLI) Start(args ...string) {
	if args == nil {
		args = os.Args
	}

	if len(args) > 1 {
		args = args[1:]
	} else {
		args = []string{}
	}

	// parse flags and args
	args = cmd.parseFlags(args)

	// Show a version
	if len(cmd.Version()) > 0 && cmd.Flag("version").Get() == true {
		fmt.Fprintln(cmd.StdOutput(), cmd.Name(), cmd.Version())
		return
	}

	// Show Help
	if cmd.Flag("help").Get() == true {
		cmd.Usage()
		return
	}

	// Parse Params
	args = cmd.parseParams(args)

	var subCommandsParsed bool
	if args, subCommandsParsed = cmd.parseSubCommands(args); subCommandsParsed {
		return
	}

	cmd.assignUnparsedArgs(args)

	// Run the function
	cmd.fn(cmd)
}
951479
func (m *Aggregator) StartLoop() {
	bufferLen := metricTransmitInterval / int(m.produceInterval)
	buffer := make([]float64, bufferLen)
	go getMetricsForever(m)

	for {
		for i := 0; i < bufferLen; i++ {
			buffer[i] = <-m.metricStream
		}
		stats, allZero := newStatMetricDatum(m.metricName, buffer, m.unitName)

		if ShouldTransmitZero || !allZero {
			debug("batching metric:", m.metricName, stats)
			m.batchStream <- stats
		}
	}
}
252987
func (awsManager *AwsManager) ShutdownStart() error {
	awsManager.ticker = time.NewTicker(awsManager.config.PingTime)
	go func() {
		for {
			awsManager.gs.ReportError(awsManager.api.SendHeartbeat(
				awsManager.autoscalingGroupName,
				awsManager.lifecycleActionToken,
			))
			<-awsManager.ticker.C
		}
	}()
	return nil
}