def start(self, config_path, non_block=False): self.status = ServerStatus.Starting self.publish('on_before_server_start', {'server':self, 'context':self.context}) self.context.load_settings(abspath(join(self.root_dir, config_path))) self.cache = Cache(size=1000, age="5s", log=cherrypy.log) self.context.load_apps() self.apps = self.context.apps self.app_paths = self.context.app_paths self.app_modules = self.context.app_modules if self.context.settings.Ion.as_bool('debug'): logging.basicConfig() logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO) logging.getLogger('sqlalchemy.orm.unitofwork').\ setLevel(logging.DEBUG) self.import_template_filters() self.import_controllers() if self.context.settings.Ion.pid_file: p = PIDFile(cherrypy.engine, self.context.settings.Ion.pid_file) p.subscribe() self.run_server(non_block) self.status = ServerStatus.Started self.publish('on_after_server_start', {'server':self, 'context':self.context})
def start(self, blocking=True): """Configure and start the server.""" self.configure() url_base = self.config['web_server']['url_base'] config = self.config.get('web_server', {}) config['engine'] = engine # import DASWebServices after we run self.configure which register secmodv2 from DAS.web.das_web_srv import DASWebService obj = DASWebService(self.config) tree.mount(obj, url_base) # mount web server self.setup_kws_server() print("### DAS web server, PID=%s" % self.pid) print(pformat(tree.apps)) print(pformat(self.config)) pid = PIDFile(engine, self.pid) pid.subscribe() engine.start() print("### DAS server runs with %s threads" \ % threading.active_count()) threads = threading.enumerate() try: threads.sort() except: pass for thr in threads: print(thr) if blocking: engine.block()
def start(self, blocking=True): """Configure and start the server.""" self.configure() url_base = self.config['web_server']['url_base'] config = self.config.get('web_server', {}) config['engine'] = engine obj = DASWebService(self.config) tree.mount(obj, url_base) # mount web server self.setup_kws_server() print "### DAS web server, PID=%s" % self.pid print pformat(tree.apps) print pformat(self.config) pid = PIDFile(engine, self.pid) pid.subscribe() engine.start() print "### DAS server runs with %s threads" \ % threading.active_count() threads = threading.enumerate() threads.sort() for thr in threads: print thr if blocking: engine.block()
def start(self, blocking=True): """Configure and start the server.""" self.configure() config['engine'] = engine WebSocketPlugin(engine).subscribe() cherrypy.tools.websocket = WebSocketTool() base_url = config.get('ws_base_url', '/websocket') wsconfig = {'/ws' :{ 'tools.websocket.on': True, 'tools.websocket.handler_cls': DBSWebSocketHandler }} tree.mount(self, base_url, wsconfig) # mount WebSocket service obj = DataService() tree.mount(obj, '/dbs') # mount another data service print "Applications:", pformat(tree.apps) print "Configuration:", pformat(self.config) pid = PIDFile(engine, self.pid) pid.subscribe() engine.start() print "### number of threads with web engine %s" \ % threading.active_count() if blocking: engine.block()
class CherrypyServer(object): """Handles server config, startup and termination. """ def __init__(self, port=8080, ip='0.0.0.0', pidfilename=None, app=None, show_log=False): self._server = wsgiserver.CherryPyWSGIServer( (ip, port), app ) if pidfilename is not None: self._pidfile = PIDFile(cherrypy.engine, pidfilename) self._pidfile.subscribe() if show_log: cherrypy.log.screen = True print("CherrypyServer running at %s:%s" % (ip, port)) def start(self): """Starts the server and stop it automatically if KeyboardInterrupt. """ try: self._server.start() except KeyboardInterrupt: self._server.stop() def stpo(self): """Stops the server.""" self._server.stop() @property def server(self): """Return the server""" return self._server @property def pidfile(self): return self.pidfile
def create_pidfile(args): # Create the filename for this instance's PID file. if not args.pidfile: if args.test: args.pidfile = "/tmp/captive_portal." else: args.pidfile = "/var/run/captive_portal." full_pidfile = args.pidfile + args.interface logging.debug("Name of PID file is: %s", full_pidfile) # If a PID file already exists for this network interface, ABEND. if os.path.exists(full_pidfile): logging.error("A pidfile already exists for network interface %s.", full_pidfile) logging.error("Is a daemon already running on this interface?") exit(5) # Write the PID file of this instance to the PID file. logging.debug("Creating pidfile for network interface %s.", str(args.interface)) logging.debug("PID of process is %s.", str(os.getpid())) pid = PIDFile(cherrypy.engine, full_pidfile) pid.subscribe()
def create_pidfile(args): # Create the filename for this instance's PID file. if not args.pidfile: if args.test: args.pidfile = '/tmp/captive_portal.' else: args.pidfile = '/var/run/captive_portal.' full_pidfile = args.pidfile + args.interface logging.debug("Name of PID file is: %s", full_pidfile) # If a PID file already exists for this network interface, ABEND. if os.path.exists(full_pidfile): logging.error("A pidfile already exists for network interface %s.", full_pidfile) logging.error("Is a daemon already running on this interface?") exit(5) # Write the PID file of this instance to the PID file. logging.debug("Creating pidfile for network interface %s.", str(args.interface)) logging.debug("PID of process is %s.", str(os.getpid())) pid = PIDFile(cherrypy.engine, full_pidfile) pid.subscribe()
def start(self, blocking=True): """Configure and start the server.""" self.configure() url_base = self.config['web_server']['url_base'] config = self.config.get('web_server', {}) config['engine'] = engine obj = DASWebService(self.config) tree.mount(obj, url_base) # mount web server # DBS/Phedex Service if self.config.has_key('dbs_phedex') and \ self.config['dbs_phedex']['urls']: uri = self.config['mongodb']['dburi'] urls = {} for url in self.config['dbs_phedex']['urls']: if url.find('phedex') != -1: urls['phedex'] = url else: urls['dbs'] = url expire = self.config['dbs_phedex'].get('expire', 3600) obj = DBSPhedexService(uri, urls, expire) tree.mount(obj, '/dbs_phedex') print "### DAS web server mounted /dbs_phedex service" print "### DAS web server, PID=%s, #threads=%s" \ % (self.pid, threading.active_count()) # for thr in threading.enumerate(): # print thr print pformat(tree.apps) print pformat(self.config) pid = PIDFile(engine, self.pid) pid.subscribe() engine.start() print "### number of threads with web engine %s" \ % threading.active_count() if blocking: engine.block()
if Options().ssl_private_key != '': cherrypy.server.ssl_private_key = Options().ssl_private_key if Options().ssl_certificate_chain != '': cherrypy.server.ssl_certificate_chain = Options().ssl_certificate_chain if Options().daemon: # Daemon info is logged by CherryPy daemon = Daemonizer(cherrypy.engine) daemon.subscribe() else: logger.info('Not running as daemon.') # PID is logged by CherryPy pid = PIDFile(cherrypy.engine, os.path.join(Options().run_dir, 'cherryblog.pid')) pid.subscribe() if Options().privileges: # Privileges are logged by CherryPy privileges = DropPrivileges(cherrypy.engine, uid=Options().uid, gid=Options().gid) privileges.subscribe() else: logger.info('No user privileges specified.') cherrypy.quickstart(Application(), config=settings) ### # # Version: 2.2.1 # Date: 2020-04-25 # Author: Yves Vindevogel (vindevoy)
raise cherrypy.HTTPRedirect('/') @cherrypy.expose def sitemap(self, **params): self.first_step('sitemap') communities = self.get_all_communities() questions = self.get_all_questions() users = self.get_all_users() document = "<?xml version='1.0' encoding='UTF-8'?>\n" document += "<urlset xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'>\n" for c in communities: document += "<url><loc>" + c.get_link(True) + "</loc><lastmod>" + str(c.created).split(' ')[0] + "</lastmod><changefreq>always</changefreq><priority>0.8</priority></url>\n" for q in questions: document += "<url><loc>" + q.get_link(True) + "</loc><lastmod>" + str(q.created).split(' ')[0] + "</lastmod><changefreq>always</changefreq><priority>0.9</priority></url>\n" for u in users: document += "<url><loc>" + u.get_link(True) + "</loc><lastmod>" + str(u.created).split(' ')[0] + "</lastmod><changefreq>always</changefreq><priority>0.8</priority></url>\n" document += "</urlset>\n" cherrypy.response.headers['Content-Type']='text/xml; charset=utf-8' return document if __name__ == "__main__": SAEnginePlugin(cherrypy.engine).subscribe() cherrypy.tools.db = SATool() if APP_RUN_AS_DAEMON: d = Daemonizer(cherrypy.engine) d.subscribe() p = PIDFile(cherrypy.engine, Ke_current_path+"/kelinux.pid") p.subscribe() cp_config['global']['log.screen'] = False cherrypy.quickstart(Main_web(), config=cp_config)
pidfile = pidfile + interface if debug: print "DEBUG: Name of PID file is: %s" % pidfile # If a PID file already exists for this network interface, ABEND. if os.path.exists(pidfile): print "ERROR: A pidfile already exists for network interface %s." % pidfile print "ERROR: Is a daemon already running on this interface?" exit(5) # Write the PID file of this instance to the PID file. if debug: print "DEBUG: Creating pidfile for network interface %s." % str(interface) print "DEBUG: PID of process is %s." % str(os.getpid()) pid = PIDFile(cherrypy.engine, pidfile) pid.subscribe() # Configure a few things about the web server so we don't have to fuss # with an extra config file, namely, the port and IP address to listen on. cherrypy.config.update({'server.socket_host':'0.0.0.0', }) cherrypy.config.update({'server.socket_port':port, }) # Set up an SSL listener running in parallel. ssl_listener = cherrypy._cpserver.Server() ssl_listener.socket_host = '0.0.0.0' ssl_listener.socket_port = ssl_port ssl_listener.ssl_certificate = ssl_cert ssl_listener.ssl_private_key = ssl_private_key ssl_listener.subscribe() # Set up the location the templates will be served out of.
@cpy.expose def stripejs(self, *args, **kwargs): print '\nArgs: {}'.format(args) print '\nKwrgs: {}'.format(kwargs) return s_template('stripe_js.mako') ## # Server if os.environ.get('DEV_STATE') == 'PRODUCTION': print '\n\n Im {}'.format(os.environ.get('DEV_STATE')) # Set PID from cherrypy.process.plugins import PIDFile p = PIDFile(cpy.engine, "/opt/python/pids/cherrypy-basic.pid") p.subscribe() # INIT from cherrypy.process.plugins import Daemonizer Daemonizer(cpy.engine).subscribe() cpy.config.update(current_dir + '/conf/cherry_conf') cpy.tree.mount(Root(), "/", config=current_dir + '/conf/cherry_conf') cpy.engine.start() cpy.engine.block() else: print '\n\n Im {}'.format(os.environ.get('DEV_STATE')) cpy.config.update('conf/cherry_conf') cpy.tree.mount(Root(), '/')