]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.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)
committerJan Fajerski <jfajerski@suse.com>
Mon, 22 Jan 2018 12:21:09 +0000 (13:21 +0100)
Calling cherrypy.engine.block() in the stanby module results in a failing
mgr failover.

Signed-off-by: Jan Fajerski <jfajerski@suse.com>
src/pybind/mgr/prometheus/module.py

index 85f78a06bafb52f0e5a9ad3780f9204d3e4cc1d2..4aef7885d7826608b57f4daa43b7719e5d735fe4 100644 (file)
@@ -138,8 +138,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
@@ -414,12 +412,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):
@@ -433,7 +435,6 @@ class StandbyModule(MgrStandbyModule):
             'engine.autoreload.on': False
         })
 
-
         module = self
 
         class Root(object):
@@ -456,13 +457,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")