Skip to content

Commit

Permalink
Merge pull request #25149 from jacksontj/saltnado
Browse files Browse the repository at this point in the history
Saltnado multiprocess support
  • Loading branch information
Mike Place committed Jul 6, 2015
2 parents a723af0 + 6aa5548 commit 2f1bad1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
9 changes: 7 additions & 2 deletions salt/netapi/rest_tornado/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 = {}
Expand All @@ -107,7 +112,7 @@ def start():
)
http_server.start(mod_opts['num_processes'])
except:
print('Rest_tornado unable to bind to port {0}'.format(mod_opts['port']))
logger.error('Rest_tornado unable to bind to port {0}'.format(mod_opts['port']), exc_info=True)
raise SystemExit(1)

try:
Expand Down
20 changes: 17 additions & 3 deletions salt/netapi/rest_tornado/saltnado.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ def __init__(self, mod_opts, opts):
'master',
opts['sock_dir'],
opts['transport'],
opts=opts)
opts=opts,
)

self.event.subscribe() # start listening for events immediately

Expand All @@ -270,8 +271,10 @@ def __init__(self, mod_opts, opts):
# 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):
Expand Down Expand Up @@ -390,6 +393,17 @@ def _verify_client(self, client):
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):
'''
Expand Down

0 comments on commit 2f1bad1

Please sign in to comment.