]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybing/mgr/prometheus: tidy up cherrypy engine start and stop
authorJan Fajerski <jfajerski@suse.com>
Thu, 30 Nov 2017 10:27:04 +0000 (11:27 +0100)
committerBoris Ranto <branto@redhat.com>
Tue, 3 Apr 2018 16:36:06 +0000 (18:36 +0200)
Calling cherrypy.engine.block() in the stanby module results in a failing
mgr failover.

Signed-off-by: Jan Fajerski <jfajerski@suse.com>
(cherry picked from commit ff471d485cd2068b6425b74a17875d8d6a823595)

src/pybind/mgr/prometheus/module.py

index 88cf04be2f3a8b48e22d6f3a4dcdca2577799394..8f0e798d685cfbdd851978ce26ff125d62adbbd6 100644 (file)
@@ -143,8 +143,6 @@ class Module(MgrModule):
 
     def __init__(self, *args, **kwargs):
         super(Module, self).__init__(*args, **kwargs)
-        self.notified = False
-        self.serving = False
         self.metrics = self._setup_static_metrics()
         self.schema = OrderedDict()
         _global_instance['plugin'] = self
@@ -473,12 +471,16 @@ class Module(MgrModule):
             'engine.autoreload.on': False
         })
         cherrypy.tree.mount(Root(), "/")
+        self.log.info('Starting engine...')
         cherrypy.engine.start()
+        self.log.info('Engine started.')
         cherrypy.engine.block()
 
     def shutdown(self):
-        self.serving = False
-        pass
+        self.log.info('Stopping engine...')
+        cherrypy.engine.wait(state=cherrypy.engine.states.STARTED)
+        cherrypy.engine.exit()
+        self.log.info('Stopped engine')
 
 
 class StandbyModule(MgrStandbyModule):
@@ -492,7 +494,6 @@ class StandbyModule(MgrStandbyModule):
             'engine.autoreload.on': False
         })
 
-
         module = self
 
         class Root(object):
@@ -515,13 +516,14 @@ class StandbyModule(MgrStandbyModule):
                 return ''
 
         cherrypy.tree.mount(Root(), '/', {})
-        cherrypy.engine.wait(state=cherrypy.engine.states.STOPPED)
         self.log.info('Starting engine...')
         cherrypy.engine.start()
+        self.log.info("Waiting for engine...")
+        cherrypy.engine.wait(state=cherrypy.engine.states.STOPPED)
         self.log.info('Engine started.')
-        cherrypy.engine.block()
 
     def shutdown(self):
-        self.log.info('Stopping engine...')
-        self.log.info('Stopped engine')
-        pass
+        self.log.info("Stopping engine...")
+        cherrypy.engine.wait(state=cherrypy.engine.states.STARTED)
+        cherrypy.engine.stop()
+        self.log.info("Stopped engine")