def start_server(options): """ Start CherryPy server """ if options['daemonize'] and options['server_user'] and options[ 'server_group']: #ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) try: from cherrypy.wsgiserver import CherryPyWSGIServer as Server except ImportError: try: from wsgiserver import CherryPyWSGIServer as Server except ImportError: from cpserver.wsgiserver import CherryPyWSGIServer as Server from django.core.handlers.wsgi import WSGIHandler server = Server((options['host'], int(options['port'])), WSGIHandler(), int(options['threads']), options['server_name'], request_queue_size=int(options['request_queue_size'])) if options['ssl_certificate'] and options['ssl_private_key']: server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] try: server.start() except KeyboardInterrupt: server.stop()
def start_server(options, settings): """ Start CherryPy server """ if options['daemonize'] and options['server_user'] and options['server_group']: #ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) from cherrypy.wsgiserver import CherryPyWSGIServer as Server from django.core.handlers.wsgi import WSGIHandler from django.core.servers.basehttp import AdminMediaHandler app = AdminMediaHandler(WSGIHandler()) server = Server( (options['host'], int(options['port'])), app, int(options['threads']), options['server_name'] ) if options['ssl_certificate'] and options['ssl_private_key']: server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] try: server.start() except KeyboardInterrupt: server.stop()
def start_server(options): """ Start CherryPy server. DEPRICATED>>>> Saving this function for future readers to use. """ if options['daemonize'] and options['server_user'] and options['server_group']: #ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) from cherrypy.wsgiserver import CherryPyWSGIServer as Server from django.core.handlers.wsgi import WSGIHandler server = Server( (options['host'], int(options['port'])), WSGIHandler(), int(options['threads']), options['server_name'] ) if options['ssl_certificate'] and options['ssl_private_key']: server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] try: server.start() except KeyboardInterrupt: server.stop()
def start_server(options): """ Start CherryPy server """ if options['daemonize'] and options['server_user'] and options['server_group']: #ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) try: from cherrypy.wsgiserver import CherryPyWSGIServer as Server except ImportError: try: from wsgiserver import CherryPyWSGIServer as Server except ImportError: from cpserver.wsgiserver import CherryPyWSGIServer as Server from django.core.handlers.wsgi import WSGIHandler server = Server( (options['host'], int(options['port'])), WSGIHandler(), int(options['threads']), options['server_name'], request_queue_size=int(options['request_queue_size']) ) if options['ssl_certificate'] and options['ssl_private_key']: server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] try: server.start() except KeyboardInterrupt: server.stop()
def start_server(options): """ Start CherryPy server """ if options['daemonize'] and options['server_user'] and options[ 'server_group']: #ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) from cherrypy.wsgiserver import CherryPyWSGIServer as Server from django.core.handlers.wsgi import WSGIHandler app = WSGIHandler() server = Server((options['host'], int(options['port'])), app, int(options['threads']), options['server_name'], timeout=2, shutdown_timeout=2) if options['ssl_certificate'] and options['ssl_private_key']: server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] try: server.start() except KeyboardInterrupt: server.stop()
def start_server(options): """ Start CherryPy server """ if options['daemonize'] and options['server_user'] and options['server_group']: #ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) from cherrypy.wsgiserver import CherryPyWSGIServer as Server import cherrypy from django.core.handlers.wsgi import WSGIHandler if options['static']: # If we want a static directory, wrap the regular app # with cherrypy.tree.mount() to serve static dir. app = WSGIHandler() cherrypy.config.update({'global': {'log.screen': True}}) conf = { '/' : { 'tools.wsgiapp.on': True, 'tools.wsgiapp.app': app }, '/static' : { 'tools.staticdir.on': True, 'tools.staticdir.dir': options['static'] } } full_app = cherrypy.tree.mount(app, '/', config=conf) else: full_app = WSGIHandler() server = Server( (options['host'], int(options['port'])), full_app, int(options['threads']), options['server_name'] ) if options['ssl_certificate'] and options['ssl_private_key']: server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] try: server.start() except KeyboardInterrupt: server.stop()
def start_server (options): if options['daemonize']: if options['server_user'] and options['server_group']: change_uid_gid(options['server_user'], options['server_group']) if options['workdir']: become_daemon(our_home_dir=options['workdir']) else: become_daemon() fp = open(options['pidfile'], 'w') fp.write("%d\n" % os.getpid()) fp.close() d = WSGIPathInfoDispatcher({'/static': static, '/': WSGIHandler()}) SERVER = Server( (options['host'], int(options['port'])), d, numthreads=int(options['threads']), max=int(options['threads']), server_name=options['server_name'], shutdown_timeout = int(options['shutdown_timeout']), request_queue_size = int(options['request_queue_size']) ) if options['ssl_certificate'].lower() == 'none' or options['ssl_private_key'].lower() == 'none': pass else: if not os.path.exists(options['ssl_certificate']) or not os.path.exists(options['ssl_private_key']): if options['ssl_certificate'] == settings.SERVER_CERT and options['ssl_private_key'] == settings.SERVER_KEY: generate_cert() else: raise Exception('Invalid Certificate or Key Path') SERVER.ssl_certificate = options['ssl_certificate'] SERVER.ssl_private_key = options['ssl_private_key'] try: SERVER.start() except KeyboardInterrupt: SERVER.stop()
def start_server(options): """ Start CherryPy server """ if options['daemonize'] and options['server_user'] and options[ 'server_group']: #ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) from cherrypy.wsgiserver import CherryPyWSGIServer as Server from django.core.handlers.wsgi import WSGIHandler server = Server((options['host'], int(options['port'])), WSGIHandler(), int(options['threads']), options['server_name'], timeout=int(options['timeout'])) if cherrypy.__version__ >= '3.2.0': #3.2 and beyond usage of ssl_adapter try: #use the openssl adapter if available from cherrypy.wsgiserver.ssl_pyopenssl import pyOpenSSLAdapter as sslAdapter except ImportError: from cherrypy.wsgiserver.ssl_builtin import BuiltinSSLAdapter as sslAdapter if options['ssl_certificate'] and options['ssl_private_key']: if options['ssl_certificate_chain']: chain = options['ssl_certificate_chain'] else: chain = None server.ssl_adapter = sslAdapter(options['ssl_certificate'], options['ssl_private_key'], certificate_chain=chain) else: #legacy older ssl setup method server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] if options['ssl_certificate_chain']: server.ssl_certificate_chain = options['ssl_certificate_chain'] try: server.start() except KeyboardInterrupt: server.stop()
def start_server(options): """ Start CherryPy server Want SSL support? a. The new (3.1 or 3.2) way: Just set server.ssl_adapter to an SSLAdapter instance. b. The old way (deprecated way) is to set these attributes: server.ssl_certificate = <filename> server.ssl_private_key = <filename> But this is the only way from the management command line in the future I may need to adapt this to use a server.ssl_adapter """ if options['daemonize'] and options['server_user'] and options['server_group']: # ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) # from django_wsgiserver.wsgiserver import CherryPyWSGIServer from cherrypy.wsgiserver import CherryPyWSGIServer from django.core.handlers.wsgi import WSGIHandler app = WSGIHandler() # if options['adminserve']: # serve the admin media too # AdminMediaHandler is middleware for local use # import django.core.servers.basehttp # app = django.core.servers.basehttp.AdminMediaHandler(app) server = CherryPyWSGIServer( (options['host'], int(options['port'])), app, int(options['threads']), options['server_name'] ) if options['ssl_certificate'] and options['ssl_private_key']: server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] try: logging.debug('starting server with options:\n%s' % pformat(options)) server.start() except KeyboardInterrupt: server.stop()
def start_server(options): """ Start CherryPy server """ if options["daemonize"] and options["server_user"] and options["server_group"]: # ensure the that the daemon runs as specified user change_uid_gid(options["server_user"], options["server_group"]) from cherrypy.wsgiserver import CherryPyWSGIServer as Server from django.core.handlers.wsgi import WSGIHandler server = Server( (options["host"], int(options["port"])), WSGIHandler(), int(options["threads"]), options["server_name"] ) if options["ssl_certificate"] and options["ssl_private_key"]: server.ssl_certificate = options["ssl_certificate"] server.ssl_private_key = options["ssl_private_key"] try: server.start() except KeyboardInterrupt: server.stop()
def main(): cherrypy.config.update({'error_page.404': err_pages.err_404}) # = Daemonizer(cherrypy.engine) #d.subscribe() AppDispatcher = WSGIPathInfoDispatcher({ '/': cherrypy.tree.mount(Main(), '/', config=config), #'/login': LoginApp, '/file': FileApp }) server = CherryPyWSGIServer((settings['ip'], settings['port']), AppDispatcher, server_name=render('__server_info__'), numthreads=100, request_queue_size=70) serverSSL = None if settings.has_key('ssl_certificate') and settings.has_key( 'ssl_private_key'): if os.path.exists(settings['ssl_certificate']) and os.path.exists( settings['ssl_private_key']): serverSSL = CherryPyWSGIServer( (settings['ip'], settings['sslport']), AppDispatcher, server_name=render('__server_info__'), numthreads=100, request_queue_size=70) serverSSL.ssl_certificate = settings['ssl_certificate'] serverSSL.ssl_private_key = settings['ssl_private_key'] s2 = ServerAdapter(cherrypy.engine, serverSSL) s2.subscribe() s1 = ServerAdapter(cherrypy.engine, server) s1.subscribe() check_create_db(settings['db_name'], settings['db_name']) cherrypy.engine.timeout_monitor.unsubscribe() cherrypy.engine.start() cherrypy.engine.block()
def main(): cherrypy.config.update({'error_page.404': err_pages.err_404}) # = Daemonizer(cherrypy.engine) #d.subscribe() AppDispatcher = WSGIPathInfoDispatcher({'/': cherrypy.tree.mount(Main(),'/',config=config), #'/login': LoginApp, '/file': FileApp }) server = CherryPyWSGIServer( (settings['ip'], settings['port']), AppDispatcher, server_name=render('__server_info__'), numthreads=100, request_queue_size=70 ) serverSSL = None if settings.has_key('ssl_certificate') and settings.has_key('ssl_private_key'): if os.path.exists(settings['ssl_certificate']) and os.path.exists(settings['ssl_private_key']): serverSSL = CherryPyWSGIServer( (settings['ip'], settings['sslport']), AppDispatcher, server_name=render('__server_info__'), numthreads=100, request_queue_size=70 ) serverSSL.ssl_certificate = settings['ssl_certificate'] serverSSL.ssl_private_key = settings['ssl_private_key'] s2 = ServerAdapter(cherrypy.engine, serverSSL) s2.subscribe() s1 = ServerAdapter(cherrypy.engine, server) s1.subscribe() check_create_db(settings['db_name'],settings['db_name']) cherrypy.engine.timeout_monitor.unsubscribe() cherrypy.engine.start() cherrypy.engine.block()
def start_server(options): """ Start CherryPy server """ if options['daemonize'] and options['server_user'] and options['server_group']: #ensure the that the daemon runs as specified user change_uid_gid(options['server_user'], options['server_group']) from cherrypy.wsgiserver import CherryPyWSGIServer as Server from django.core.handlers.wsgi import WSGIHandler import cherrypy pth = os.path.join(os.path.abspath('..'), 'media') pth_ext = os.path.exists(pth) #MEDIA_ROOT = '/var/projects/%s:%s/media/' % (options['server_name'], int(options['port']) + 1) ''' try: if pth_ext: MEDIA_ROOT = pth else: print "Media path is %s" % MEDIA_ROOT except: print "Could not create dynamic MEDIA_ROOT path" print "%s is missing" % pth cherrypy.config['tools.staticdir.on']= True cherrypy.config['tools.staticdir.dir'] = pth ''' server = Server( (options['host'], int(options['port'])), WSGIHandler(), int(options['threads']), options['server_name'] ) if options['ssl_certificate'] and options['ssl_private_key']: server.ssl_certificate = options['ssl_certificate'] server.ssl_private_key = options['ssl_private_key'] #'tools.staticdir.on': True, #'tools.staticdir.dir': os.path.join(os.path.abspath('..'), 'media'), try: p('Starting server') server.start() #media_server.start() #from cherrypy.process.servers import ServerAdapter #s1 = ServerAdapter(cherrypy.engine, server) #s2 = ServerAdapter(cherrypy.engine, media_server) #s1.subscribe() #s2.subscribe() #cherrypy.engine.start() except KeyboardInterrupt: p('Stopping server') server.stop()
sslAdapter.certbase = certbase server.ssl_adapter = sslAdapter server.certbase = certbase server.serv_certbase = serv_certbase server.rights = rights server.group_rights = group_rights server.sids = sids server.pids = pids server.sids_file = sids_file server.pids_file = pids_file server.data_path = data_path server.cert_path = cert_path server.ssl_certificate = cert server.ssl_private_key = key from OpenSSL.SSL import Error as SSLError import socket try: if args.pidfile: try: open(args.pidfile,"w").write(str(os.getpid())) except OSError: sys.stderr.write(_("failed to create PID file %s") \ %args.pidfile+"\n") sys.exit(1) # For cleaning of sessions at server reboot from clean import clean clean(sids_file, pids_file, sids_pids, sids, pids) print _("Server started") server.start()
def start_server (options): if options['daemonize']: if options['server_user'] and options['server_group']: change_uid_gid(options['server_user'], options['server_group']) if options['workdir']: become_daemon(our_home_dir=options['workdir']) else: become_daemon() fp = open(options['pidfile'], 'w') fp.write("%d\n" % os.getpid()) fp.close() d = WSGIPathInfoDispatcher({'/static': static, '/': WSGIHandler()}) SERVER = Server( (options['host'], int(options['port'])), d, numthreads=int(options['threads']), max=int(options['threads']), server_name=options['server_name'], shutdown_timeout = int(options['shutdown_timeout']), request_queue_size = int(options['request_queue_size']) ) SERVER2 = Server( (options['host'], int(options['eport'])), d, numthreads=int(options['threads']), max=int(options['threads']), server_name=options['server_name'], shutdown_timeout = int(options['shutdown_timeout']), request_queue_size = int(options['request_queue_size']) ) if options['ssl_certificate'].lower() == 'none' or options['ssl_private_key'].lower() == 'none': pass else: if not os.path.exists(options['ssl_certificate']) or not os.path.exists(options['ssl_private_key']): if options['ssl_certificate'] == settings.SERVER_CERT and options['ssl_private_key'] == settings.SERVER_KEY: generate_cert() else: raise Exception('Invalid Certificate or Key Path') SERVER.ssl_certificate = options['ssl_certificate'] SERVER.ssl_private_key = options['ssl_private_key'] try: if options['ssl_certificate'].lower() == 'none' or options['ssl_private_key'].lower() == 'none': SERVER.start() else: from multiprocessing import Process p = Process(target=SERVER.start) p.start() SERVER2.start() except KeyboardInterrupt: SERVER.stop() if options['ssl_certificate'].lower() == 'none' or options['ssl_private_key'].lower() == 'none': pass else: SERVER2.stop()