server|cmd: refactor monitors chan
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
8f5e37a83c
commit
d6c32fa88e
2 changed files with 15 additions and 15 deletions
|
@ -167,7 +167,7 @@ func catchShutdown(gserver *grpc.Server, sserver *server.Server, hserver *http.S
|
||||||
gserver.GracefulStop()
|
gserver.GracefulStop()
|
||||||
hserver.Shutdown(context.Background())
|
hserver.Shutdown(context.Background())
|
||||||
sserver.StopStreamServer()
|
sserver.StopStreamServer()
|
||||||
sserver.StopExitMonitor()
|
sserver.StopMonitors()
|
||||||
if err := sserver.Shutdown(); err != nil {
|
if err := sserver.Shutdown(); err != nil {
|
||||||
logrus.Warnf("error shutting down main service %v", err)
|
logrus.Warnf("error shutting down main service %v", err)
|
||||||
}
|
}
|
||||||
|
@ -515,10 +515,10 @@ func main() {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
streamServerCloseCh := service.StreamingServerCloseChan()
|
streamServerCloseCh := service.StreamingServerCloseChan()
|
||||||
serverExitMonitorCh := service.ExitMonitorCloseChan()
|
serverMonitorsCh := service.MonitorsCloseChan()
|
||||||
select {
|
select {
|
||||||
case <-streamServerCloseCh:
|
case <-streamServerCloseCh:
|
||||||
case <-serverExitMonitorCh:
|
case <-serverMonitorsCh:
|
||||||
case <-serverCloseCh:
|
case <-serverCloseCh:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -526,7 +526,7 @@ func main() {
|
||||||
|
|
||||||
<-streamServerCloseCh
|
<-streamServerCloseCh
|
||||||
logrus.Debug("closed stream server")
|
logrus.Debug("closed stream server")
|
||||||
<-serverExitMonitorCh
|
<-serverMonitorsCh
|
||||||
logrus.Debug("closed exit monitor")
|
logrus.Debug("closed exit monitor")
|
||||||
<-serverCloseCh
|
<-serverCloseCh
|
||||||
logrus.Debug("closed main server")
|
logrus.Debug("closed main server")
|
||||||
|
|
|
@ -66,9 +66,9 @@ type Server struct {
|
||||||
appArmorEnabled bool
|
appArmorEnabled bool
|
||||||
appArmorProfile string
|
appArmorProfile string
|
||||||
|
|
||||||
bindAddress string
|
bindAddress string
|
||||||
stream streamService
|
stream streamService
|
||||||
exitMonitorChan chan struct{}
|
monitorsChan chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopStreamServer stops the stream server
|
// StopStreamServer stops the stream server
|
||||||
|
@ -211,7 +211,7 @@ func New(config *Config) (*Server, error) {
|
||||||
seccompEnabled: seccomp.IsEnabled(),
|
seccompEnabled: seccomp.IsEnabled(),
|
||||||
appArmorEnabled: apparmor.IsEnabled(),
|
appArmorEnabled: apparmor.IsEnabled(),
|
||||||
appArmorProfile: config.ApparmorProfile,
|
appArmorProfile: config.ApparmorProfile,
|
||||||
exitMonitorChan: make(chan struct{}),
|
monitorsChan: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.seccompEnabled {
|
if s.seccompEnabled {
|
||||||
|
@ -355,14 +355,14 @@ func (s *Server) CreateMetricsEndpoint() (*http.ServeMux, error) {
|
||||||
return mux, nil
|
return mux, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopExitMonitor stops the exit monitor
|
// StopMonitors stops al the monitors
|
||||||
func (s *Server) StopExitMonitor() {
|
func (s *Server) StopMonitors() {
|
||||||
close(s.exitMonitorChan)
|
close(s.monitorsChan)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExitMonitorCloseChan returns the close chan for the exit monitor
|
// MonitorsCloseChan returns the close chan for the exit monitor
|
||||||
func (s *Server) ExitMonitorCloseChan() chan struct{} {
|
func (s *Server) MonitorsCloseChan() chan struct{} {
|
||||||
return s.exitMonitorChan
|
return s.monitorsChan
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartExitMonitor start a routine that monitors container exits
|
// StartExitMonitor start a routine that monitors container exits
|
||||||
|
@ -410,7 +410,7 @@ func (s *Server) StartExitMonitor() {
|
||||||
logrus.Debugf("watch error: %v", err)
|
logrus.Debugf("watch error: %v", err)
|
||||||
close(done)
|
close(done)
|
||||||
return
|
return
|
||||||
case <-s.exitMonitorChan:
|
case <-s.monitorsChan:
|
||||||
logrus.Debug("closing exit monitor...")
|
logrus.Debug("closing exit monitor...")
|
||||||
close(done)
|
close(done)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue