Esempio n. 1
0
func main() {
	settings := evergreen.GetSettingsOrExit()
	if settings.Runner.LogFile != "" {
		evergreen.SetLogger(settings.Runner.LogFile)
	}

	go util.DumpStackOnSIGQUIT(os.Stdout)
	db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(settings))

	// just run one process if an argument was passed in
	if flag.Arg(0) != "" {
		err := runProcessByName(flag.Arg(0), settings)
		if err != nil {
			evergreen.Logger.Logf(slogger.ERROR, "Error: %v", err)
			os.Exit(1)
		}
		return
	}

	if settings.Runner.IntervalSeconds <= 0 {
		evergreen.Logger.Logf(slogger.WARN, "Interval set to %vs (<= 0s) using %vs instead",
			settings.Runner.IntervalSeconds, runInterval)
	} else {
		runInterval = settings.Runner.IntervalSeconds
	}

	// start and schedule runners
	wg := &sync.WaitGroup{}
	ch := startRunners(wg, settings)
	go listenForSIGTERM(ch)

	// wait for all the processes to exit
	wg.Wait()
	evergreen.Logger.Logf(slogger.INFO, "Cleanly terminated all %v processes", len(Runners))
}
Esempio n. 2
0
// StartBackgroundActions spawns goroutines that monitor various parts of the
// execution - heartbeats, timeouts, logging, etc.
func (agt *Agent) StartBackgroundActions(signalHandler TerminateHandler) chan FinalTaskFunc {
	completed := make(chan FinalTaskFunc)
	agt.heartbeater.StartHeartbeating()
	agt.statsCollector.LogStats(agt.taskConfig.Expansions)
	agt.timeoutWatcher.NotifyTimeouts(agt.signalChan)
	go signalHandler.HandleSignals(agt, completed)

	// listen for SIGQUIT and dump a stack trace to system logs if received.
	go util.DumpStackOnSIGQUIT(evergreen.NewInfoLoggingWriter(agt.logger.System))
	return completed
}
Esempio n. 3
0
func main() {
	go util.DumpStackOnSIGQUIT(os.Stdout)
	settings := evergreen.GetSettingsOrExit()
	home := evergreen.FindEvergreenHome()
	uis, err := service.NewUIServer(settings, home)
	if err != nil {
		fmt.Println("Failed to create ui server: %v", err)
		os.Exit(1)
	}
	router, err := uis.NewRouter()
	if err != nil {
		fmt.Println("Failed to create router:", err)
		os.Exit(1)
	}

	webHome := filepath.Join(home, "public")

	functionOptions := service.FuncOptions{webHome, settings.Ui.HelpUrl, true, router}

	functions, err := service.MakeTemplateFuncs(functionOptions, settings.SuperUsers)
	htmlFunctions := htmlTemplate.FuncMap(functions)
	textFunctions := textTemplate.FuncMap(functions)

	if err != nil {
		fmt.Println("Failed to create template function map:", err)
		os.Exit(1)
	}

	uis.Render = render.New(render.Options{
		Directory:    filepath.Join(home, service.WebRootPath, service.Templates),
		DisableCache: !settings.Ui.CacheTemplates,
		HtmlFuncs:    htmlFunctions,
		TextFuncs:    textFunctions,
	})
	err = uis.InitPlugins()
	if err != nil {
		fmt.Println("WARNING: Error initializing plugins:", err)
	}

	n := negroni.New()
	n.Use(negroni.NewStatic(http.Dir(webHome)))
	n.Use(service.NewLogger())
	n.Use(negroni.HandlerFunc(service.UserMiddleware(uis.UserManager)))
	n.UseHandler(router)
	graceful.Run(settings.Ui.HttpListenAddr, requestTimeout, n)
	evergreen.Logger.Logf(slogger.INFO, "UI server cleanly terminated")
}
Esempio n. 4
0
func main() {
	go util.DumpStackOnSIGQUIT(os.Stdout)
	settings := evergreen.GetSettingsOrExit()
	if settings.Api.LogFile != "" {
		evergreen.SetLogger(settings.Api.LogFile)
	}

	db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(settings))

	tlsConfig, err := util.MakeTlsConfig(settings.Api.HttpsCert, settings.Api.HttpsKey)
	if err != nil {
		evergreen.Logger.Logf(slogger.ERROR, "Failed to make TLS config: %v", err)
		os.Exit(1)
	}

	nonSSL, err := service.GetListener(settings.Api.HttpListenAddr)
	if err != nil {
		evergreen.Logger.Logf(slogger.ERROR, "Failed to get HTTP listener: %v", err)
		os.Exit(1)
	}

	ssl, err := service.GetTLSListener(settings.Api.HttpsListenAddr, tlsConfig)
	if err != nil {
		evergreen.Logger.Logf(slogger.ERROR, "Failed to get HTTPS listener: %v", err)
		os.Exit(1)
	}

	// Start SSL and non-SSL servers in independent goroutines, but exit
	// the process if either one fails
	as, err := service.NewAPIServer(settings, plugin.APIPlugins)
	if err != nil {
		evergreen.Logger.Logf(slogger.ERROR, "Failed to create API server: %v", err)
		os.Exit(1)
	}

	handler, err := as.Handler()
	if err != nil {
		evergreen.Logger.Logf(slogger.ERROR, "Failed to get API route handlers: %v", err)
		os.Exit(1)
	}

	server := &http.Server{Handler: handler}

	errChan := make(chan error, 2)

	go func() {
		evergreen.Logger.Logf(slogger.INFO, "Starting non-SSL API server")
		err := graceful.Serve(server, nonSSL, requestTimeout)
		if err != nil {
			if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") {
				evergreen.Logger.Logf(slogger.WARN, "non-SSL API server error: %v", err)
			} else {
				err = nil
			}
		}
		evergreen.Logger.Logf(slogger.INFO, "non-SSL API server cleanly terminated")
		errChan <- err
	}()

	go func() {
		evergreen.Logger.Logf(slogger.INFO, "Starting SSL API server")
		err := graceful.Serve(server, ssl, requestTimeout)
		if err != nil {
			if opErr, ok := err.(*net.OpError); !ok || (ok && opErr.Op != "accept") {
				evergreen.Logger.Logf(slogger.WARN, "SSL API server error: %v", err)
			} else {
				err = nil
			}
		}
		evergreen.Logger.Logf(slogger.INFO, "SSL API server cleanly terminated")
		errChan <- err
	}()

	exitCode := 0

	for i := 0; i < 2; i++ {
		if err := <-errChan; err != nil {
			evergreen.Logger.Logf(slogger.ERROR, "Error returned from API server: %v", err)
			exitCode = 1
		}
	}

	os.Exit(exitCode)
}