17bc6d8d3SBrad Bishop#!/usr/bin/env python 27bc6d8d3SBrad Bishop 37bc6d8d3SBrad Bishop# Contributors Listed Below - COPYRIGHT 2016 47bc6d8d3SBrad Bishop# [+] International Business Machines Corp. 57bc6d8d3SBrad Bishop# 67bc6d8d3SBrad Bishop# 77bc6d8d3SBrad Bishop# Licensed under the Apache License, Version 2.0 (the "License"); 87bc6d8d3SBrad Bishop# you may not use this file except in compliance with the License. 97bc6d8d3SBrad Bishop# You may obtain a copy of the License at 107bc6d8d3SBrad Bishop# 117bc6d8d3SBrad Bishop# http://www.apache.org/licenses/LICENSE-2.0 127bc6d8d3SBrad Bishop# 137bc6d8d3SBrad Bishop# Unless required by applicable law or agreed to in writing, software 147bc6d8d3SBrad Bishop# distributed under the License is distributed on an "AS IS" BASIS, 157bc6d8d3SBrad Bishop# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 167bc6d8d3SBrad Bishop# implied. See the License for the specific language governing 177bc6d8d3SBrad Bishop# permissions and limitations under the License. 187bc6d8d3SBrad Bishop 197bc6d8d3SBrad Bishop 207bc6d8d3SBrad Bishopimport sys 217bc6d8d3SBrad Bishopimport os 227bc6d8d3SBrad Bishopimport gevent 237bc6d8d3SBrad Bishopfrom gevent.pywsgi import WSGIServer 24*0fe213fbSDeepak Kodihallihave_wsock = True 25*0fe213fbSDeepak Kodihallitry: 26*0fe213fbSDeepak Kodihalli from geventwebsocket.handler import WebSocketHandler 27*0fe213fbSDeepak Kodihalliexcept ImportError: 28*0fe213fbSDeepak Kodihalli have_wsock = False 297bc6d8d3SBrad Bishop 307bc6d8d3SBrad Bishopif __name__ == '__main__': 317bc6d8d3SBrad Bishop if len(sys.argv) < 2: 327bc6d8d3SBrad Bishop sys.stderr.write('WSGI application required!') 337bc6d8d3SBrad Bishop sys.exit(1) 347bc6d8d3SBrad Bishop 357bc6d8d3SBrad Bishop exec 'from obmc.wsgi.apps.%s import App' % sys.argv[1] 367bc6d8d3SBrad Bishop 377bc6d8d3SBrad Bishop default_cert = os.path.join( 387bc6d8d3SBrad Bishop sys.prefix, 'share', os.path.basename(__file__), 'cert.pem') 397bc6d8d3SBrad Bishop 40*0fe213fbSDeepak Kodihalli kw = {} 41*0fe213fbSDeepak Kodihalli if have_wsock: 42*0fe213fbSDeepak Kodihalli kw['have_wsock'] = True 43*0fe213fbSDeepak Kodihalli app = App(**kw) 447bc6d8d3SBrad Bishop 457bc6d8d3SBrad Bishop if os.environ.get('LISTEN_PID', None) == str(os.getpid()): 467bc6d8d3SBrad Bishop FIRST_SYSTEMD_SOCKET_FD = 3 477bc6d8d3SBrad Bishop bind = gevent.socket.fromfd(FIRST_SYSTEMD_SOCKET_FD, 487bc6d8d3SBrad Bishop gevent.socket.AF_INET, 497bc6d8d3SBrad Bishop gevent.socket.SOCK_STREAM) 507bc6d8d3SBrad Bishop else: 517bc6d8d3SBrad Bishop bind = ('', 443) 527bc6d8d3SBrad Bishop 53*0fe213fbSDeepak Kodihalli kw = {} 54*0fe213fbSDeepak Kodihalli if have_wsock: 55*0fe213fbSDeepak Kodihalli kw['handler_class'] = WebSocketHandler 567bc6d8d3SBrad Bishop server = WSGIServer( 57*0fe213fbSDeepak Kodihalli bind, app, keyfile=default_cert, certfile=default_cert, **kw) 587bc6d8d3SBrad Bishop server.serve_forever() 59