1*7bc6d8d3SBrad Bishop#!/usr/bin/env python 2*7bc6d8d3SBrad Bishop 3*7bc6d8d3SBrad Bishop# Contributors Listed Below - COPYRIGHT 2016 4*7bc6d8d3SBrad Bishop# [+] International Business Machines Corp. 5*7bc6d8d3SBrad Bishop# 6*7bc6d8d3SBrad Bishop# 7*7bc6d8d3SBrad Bishop# Licensed under the Apache License, Version 2.0 (the "License"); 8*7bc6d8d3SBrad Bishop# you may not use this file except in compliance with the License. 9*7bc6d8d3SBrad Bishop# You may obtain a copy of the License at 10*7bc6d8d3SBrad Bishop# 11*7bc6d8d3SBrad Bishop# http://www.apache.org/licenses/LICENSE-2.0 12*7bc6d8d3SBrad Bishop# 13*7bc6d8d3SBrad Bishop# Unless required by applicable law or agreed to in writing, software 14*7bc6d8d3SBrad Bishop# distributed under the License is distributed on an "AS IS" BASIS, 15*7bc6d8d3SBrad Bishop# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 16*7bc6d8d3SBrad Bishop# implied. See the License for the specific language governing 17*7bc6d8d3SBrad Bishop# permissions and limitations under the License. 18*7bc6d8d3SBrad Bishop 19*7bc6d8d3SBrad Bishop 20*7bc6d8d3SBrad Bishopimport sys 21*7bc6d8d3SBrad Bishopimport os 22*7bc6d8d3SBrad Bishopimport gevent 23*7bc6d8d3SBrad Bishopfrom gevent.pywsgi import WSGIServer 24*7bc6d8d3SBrad Bishop 25*7bc6d8d3SBrad Bishopif __name__ == '__main__': 26*7bc6d8d3SBrad Bishop if len(sys.argv) < 2: 27*7bc6d8d3SBrad Bishop sys.stderr.write('WSGI application required!') 28*7bc6d8d3SBrad Bishop sys.exit(1) 29*7bc6d8d3SBrad Bishop 30*7bc6d8d3SBrad Bishop exec 'from obmc.wsgi.apps.%s import App' % sys.argv[1] 31*7bc6d8d3SBrad Bishop 32*7bc6d8d3SBrad Bishop default_cert = os.path.join( 33*7bc6d8d3SBrad Bishop sys.prefix, 'share', os.path.basename(__file__), 'cert.pem') 34*7bc6d8d3SBrad Bishop 35*7bc6d8d3SBrad Bishop app = App() 36*7bc6d8d3SBrad Bishop 37*7bc6d8d3SBrad Bishop if os.environ.get('LISTEN_PID', None) == str(os.getpid()): 38*7bc6d8d3SBrad Bishop FIRST_SYSTEMD_SOCKET_FD = 3 39*7bc6d8d3SBrad Bishop bind = gevent.socket.fromfd(FIRST_SYSTEMD_SOCKET_FD, 40*7bc6d8d3SBrad Bishop gevent.socket.AF_INET, 41*7bc6d8d3SBrad Bishop gevent.socket.SOCK_STREAM) 42*7bc6d8d3SBrad Bishop else: 43*7bc6d8d3SBrad Bishop bind = ('', 443) 44*7bc6d8d3SBrad Bishop 45*7bc6d8d3SBrad Bishop server = WSGIServer( 46*7bc6d8d3SBrad Bishop bind, app, keyfile=default_cert, certfile=default_cert) 47*7bc6d8d3SBrad Bishop server.serve_forever() 48