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