Source

nx-web / serve.py

#!/usr/bin/env python

import argparse
import json
import logging.config
import geventwebsocket

from nxweb.data import cache, dkvs

from nxweb.apps import (
    cman,
    cmanws,
    auth,
    admin,
    wman,
    wmanws,
    daac,
)

from gevent.pywsgi import WSGIServer


def main():
    argparser = argparse.ArgumentParser(description="Serve nx-web applications forever.")
    argparser.add_argument('app_config_file')
    argparser.add_argument('log_config_file')
    args = argparser.parse_args()

    logging.config.fileConfig(args.log_config_file)

    with open(args.app_config_file, 'r') as app_config_file:
        config = json.loads(app_config_file.read())

    cache.initialize(**config['redis_cache'])
    dkvs.initialize(**config['riak'])

    for bucket_name in ['task_metadata', 'task_input_data_chunk', 'task_output_data_chunk']:
        print "Empty %s Bucket" % bucket_name
        dkvs.delete_all_keys(bucket_name)

    # cman --------------------------------------------------------------------
    cman_conf = config['apps']['cman']
    cman_wsgi_app = cman.make_wsgi_app(**cman_conf['pyramid_configurator_settings'])
    cman_wsgi_server = WSGIServer((cman_conf['host'], cman_conf['port']), cman_wsgi_app)
    # -------------------------------------------------------------------------
    # cmanws ------------------------------------------------------------------
    cmanws_conf = config['apps']['cmanws']
    cmanws_wsgi_server = WSGIServer((cmanws_conf['host'], cmanws_conf['port']), cmanws.websocket_app, handler_class=geventwebsocket.WebSocketHandler)
    # -------------------------------------------------------------------------

    # auth --------------------------------------------------------------------
    auth_conf = config['apps']['auth']
    auth_wsgi_app = auth.make_wsgi_app(**auth_conf['pyramid_configurator_settings'])
    auth_wsgi_server = WSGIServer((auth_conf['host'], auth_conf['port']), auth_wsgi_app)
    # -------------------------------------------------------------------------

    # admin -------------------------------------------------------------------
    admin_conf = config['apps']['admin']
    admin_conf['pyramid_configurator_settings'].update({"wmanws_config":config['apps']['wmanws']})
    admin_wsgi_app = admin.make_wsgi_app(**admin_conf['pyramid_configurator_settings'])
    admin_wsgi_server = WSGIServer((admin_conf['host'], admin_conf['port']), admin_wsgi_app)
    # -------------------------------------------------------------------------

    # wman  -------------------------------------------------------------------
    wman_conf = config['apps']['wman']
    wman_wsgi_app = wman.make_wsgi_app(**wman_conf['pyramid_configurator_settings'])
    wman_wsgi_server = WSGIServer((wman_conf['host'], wman_conf['port']), wman_wsgi_app)
    # -------------------------------------------------------------------------
    # wmanws ------------------------------------------------------------------
    wmanws_conf = config['apps']['wmanws']
    wmanws_wsgi_server = WSGIServer((wmanws_conf['host'], wmanws_conf['port']), wmanws.accept_ws_connection, handler_class=geventwebsocket.WebSocketHandler)
    # -------------------------------------------------------------------------
    import gevent
#    print dir(gevent)
#    print gevent.__path__
    # daac  -------------------------------------------------------------------
    daac_conf = config['apps']['daac']
    daac_wsgi_app = daac.make_wsgi_app(**daac_conf['pyramid_configurator_settings'])
    daac_wsgi_server = WSGIServer((daac_conf['host'], daac_conf['port']), daac_wsgi_app)
    # -------------------------------------------------------------------------

    servers = [
                cman_wsgi_server,
                cmanws_wsgi_server,
                auth_wsgi_server,
                admin_wsgi_server,
                wman_wsgi_server,
                wmanws_wsgi_server,
                daac_wsgi_server,
    ]

    try:
        for server in servers:
            print "starting server" + repr(server)
            if server is not servers[-1]:
                server.start()
            else:
                server.serve_forever()
    except KeyboardInterrupt:
        pass
    finally:
        for server in servers:
            server.stop()


main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.