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)) }
func main() { settings := evergreen.GetSettingsOrExit() if settings.Ui.LogFile != "" { evergreen.SetLogger(settings.Ui.LogFile) } db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(settings)) home := evergreen.FindEvergreenHome() userManager, err := auth.LoadUserManager(settings.AuthConfig) if err != nil { fmt.Println("Failed to create user manager:", err) os.Exit(1) } cookieStore := sessions.NewCookieStore([]byte(settings.Ui.Secret)) uis := ui.UIServer{ nil, // render settings.Ui.Url, // RootURL userManager, // User Manager *settings, // mci settings cookieStore, // cookiestore nil, // plugin panel manager } router, err := uis.NewRouter() if err != nil { fmt.Println("Failed to create router:", err) os.Exit(1) } webHome := filepath.Join(home, "public") functionOptions := ui.FuncOptions{webHome, settings.Ui.HelpUrl, true, router} functions, err := ui.MakeTemplateFuncs(functionOptions, settings.SuperUsers) 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, ui.WebRootPath, ui.Templates), DisableCache: !settings.Ui.CacheTemplates, Funcs: functions, }) 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(ui.NewLogger()) n.Use(negroni.HandlerFunc(ui.UserMiddleware(userManager))) n.UseHandler(router) graceful.Run(settings.Ui.HttpListenAddr, requestTimeout, n) evergreen.Logger.Logf(slogger.INFO, "UI server cleanly terminated") }
func main() { settings := evergreen.GetSettingsOrExit() home := evergreen.FindEvergreenHome() uis, err := ui.New(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(uis.Home, "public") functionOptions := ui.FuncOptions{webHome, uis.Settings.Ui.HelpUrl, true, router} functions, err := ui.MakeTemplateFuncs(functionOptions, uis.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(uis.Home, ui.WebRootPath, ui.Templates), DisableCache: !uis.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(ui.NewLogger()) n.Use(negroni.HandlerFunc(ui.UserMiddleware(uis.UserManager))) n.UseHandler(router) graceful.Run(uis.Settings.Ui.HttpListenAddr, requestTimeout, n) evergreen.Logger.Logf(slogger.INFO, "UI server cleanly terminated") }
func main() { settings := evergreen.GetSettingsOrExit() if settings.Api.LogFile != "" { evergreen.SetLogger(settings.Api.LogFile) } db.SetGlobalSessionProvider(db.SessionFactoryFromConfig(settings)) tlsConfig, err := util.MakeTlsConfig(settings.Expansions["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 := apiserver.GetListener(settings.Api.HttpListenAddr) if err != nil { evergreen.Logger.Logf(slogger.ERROR, "Failed to get HTTP listener: %v", err) os.Exit(1) } ssl, err := apiserver.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 := apiserver.New(settings, plugin.Published) 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) }