Enable multiprocess support in saltnado

The main exception seen is the incompatibility of debug=True and multiprocessing. In addition to that we were initing the event listener (read: zmq sockets) before the fork wich causes other issues. This patch makes rest_tornado fully multiprocess capable.

Feature for #24979
This commit is contained in:
Thomas Jackson 2015-07-03 16:11:57 -07:00
parent 9a1351eada
commit 6aa5548e2d
2 changed files with 23 additions and 4 deletions

View file

@ -46,6 +46,12 @@ def start():
if 'num_processes' not in mod_opts:
mod_opts['num_processes'] = 1
if mod_opts['num_processes'] > 1 and mod_opts.get('debug', False) is True:
raise Exception((
'Tornado\'s debug implementation is not compatible with multiprocess. '
'Either disable debug, or set num_processes to 1.'
))
paths = [
(r"/", saltnado.SaltAPIHandler),
(r"/login", saltnado.SaltAuthHandler),
@ -81,7 +87,6 @@ def start():
application.opts = __opts__
application.mod_opts = mod_opts
application.auth = salt.auth.LoadAuth(__opts__)
application.event_listener = saltnado.EventListener(mod_opts, __opts__)
# the kwargs for the HTTPServer
kwargs = {}

View file

@ -257,7 +257,8 @@ class EventListener(object):
'master',
opts['sock_dir'],
opts['transport'],
opts=opts)
opts=opts,
)
self.event.subscribe() # start listening for events immediately
@ -270,8 +271,10 @@ class EventListener(object):
# map of future -> timeout_callback
self.timeout_map = {}
self.stream = zmqstream.ZMQStream(self.event.sub,
io_loop=tornado.ioloop.IOLoop.current())
self.stream = zmqstream.ZMQStream(
self.event.sub,
io_loop=tornado.ioloop.IOLoop.current(),
)
self.stream.on_recv(self._handle_event_socket_recv)
def clean_timeout_futures(self, request):
@ -390,6 +393,17 @@ class BaseSaltAPIHandler(tornado.web.RequestHandler, SaltClientsMixIn): # pylin
self.write("We don't serve your kind here")
self.finish()
def initialize(self):
'''
Initialize the handler before requests are called
'''
if not hasattr(self.application, 'event_listener'):
logger.critical('init a listener')
self.application.event_listener = EventListener(
self.application.mod_opts,
self.application.opts,
)
@property
def token(self):
'''