From f4fdec58bdfd07af8d220eac1c02d15ee408d0c7 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Tue, 7 Mar 2017 13:20:50 -0700 Subject: [PATCH] close services in reverse order --- server/server.go | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/server/server.go b/server/server.go index edabd8147..e7b6caa42 100644 --- a/server/server.go +++ b/server/server.go @@ -169,7 +169,9 @@ func New(c *Config, buildInfo BuildInfo, logService logging.Interface) (*Server, s.appendAuthService() s.appendConfigOverrideService() s.appendTesterService() - s.appendAlertService() + + // Init alert service + s.initAlertService() // Append all dynamic services after the config override and tester services. s.appendUDFService() @@ -178,9 +180,6 @@ func New(c *Config, buildInfo BuildInfo, logService logging.Interface) (*Server, if err := s.appendInfluxDBService(); err != nil { return nil, errors.Wrap(err, "influxdb service") } - // Append these after InfluxDB because they depend on it - s.appendTaskStoreService() - s.appendReplayService() // Append Alert integration services s.appendAlertaService() @@ -196,6 +195,13 @@ func New(c *Config, buildInfo BuildInfo, logService logging.Interface) (*Server, s.appendTalkService() s.appendVictorOpsService() + // Append alert service + s.appendAlertService() + + // Append these after InfluxDB because they depend on it + s.appendTaskStoreService() + s.appendReplayService() + // Append third-party integrations if err := s.appendK8sService(); err != nil { return nil, errors.Wrap(err, "kubernetes service") @@ -261,7 +267,7 @@ func (s *Server) appendConfigOverrideService() { s.AppendService("config", srv) } -func (s *Server) appendAlertService() { +func (s *Server) initAlertService() { l := s.LogService.NewLogger("[alert] ", log.LstdFlags) srv := alert.NewService(s.config.Alert, l) @@ -271,7 +277,10 @@ func (s *Server) appendAlertService() { s.AlertService = srv s.TaskMaster.AlertService = srv - s.AppendService("alert", srv) +} + +func (s *Server) appendAlertService() { + s.AppendService("alert", s.AlertService) } func (s *Server) appendTesterService() { @@ -710,7 +719,8 @@ func (s *Server) Close() error { s.TaskMaster.StopTasks() // Close services now that all tasks are stopped. - for _, service := range s.Services { + for i := len(s.Services) - 1; i >= 0; i-- { + service := s.Services[i] s.Logger.Printf("D! closing service: %T", service) err := service.Close() if err != nil {