def main(args=None): args = parse_args(args) main_proc = rpc_server.MainProcess() config = {} # load default configuration from file for path in (args.config_file, 'config.yaml'): if path and os.path.exists(path): config = read_config(path) break process_config(config) # allow overwritting any configuration setting via env vars for k, v in os.environ.items(): if k.startswith('WORKER_'): config[k.replace("WORKER_", "").replace("_", ".").lower()] = v # make zmon worker compatible with old redis config vars if 'redis.host' in config: port = config.get('redis.port', 6379) config.update({"redis.servers":'{}:{}'.format(config["redis.host"], port)}) # save config in our settings module settings.set_workers_log_level(config.get('loglevel', 'INFO')) settings.set_external_config(config) settings.set_rpc_server_port(config.get('server.port')) logging.config.dictConfig(settings.RPC_SERVER_CONF['LOGGING']) # start the process controller main_proc.start_proc_control() # start some processes per queue according to the config queues = config['zmon.queues']['local'] for qn in queues.split(','): queue, N = (qn.rsplit('/', 1) + [DEFAULT_NUM_PROC])[:2] main_proc.proc_control.spawn_many(int(N), kwargs={"queue": queue, "flow": "simple_queue_processor"}) if not args.no_rpc: main_proc.start_rpc_server() return main_proc
def main(): # add src dir to sys.path # src_dir = os.path.abspath(os.path.dirname(__file__)) # if src_dir not in sys.path: # sys.path.append(src_dir) args = parse_args() main_proc = rpc_server.MainProcess() # load cherrypy configuration if args.config_file and os.path.exists(args.config_file): cherrypy.config.update(args.config_file) elif os.path.exists('/app/web.conf'): cherrypy.config.update('/app/web.conf') else: cherrypy.config.update('web.conf') for key in cherrypy.config.keys(): env_key = key.upper().replace('.', '_') if env_key in os.environ: cherrypy.config[key] = os.environ[env_key] # save cherrypy config in owr settings module settings.set_workers_log_level(cherrypy.config.get('loglevel', 'INFO')) settings.set_external_config(cherrypy.config) settings.set_rpc_server_port('2{}'.format('3500')) # start the process controller main_proc.start_proc_control() # start some processes per queue according to the config queues = cherrypy.config['zmon.queues']['local'] for qn in queues.split(','): queue, N = (qn.rsplit('/', 1) + [DEFAULT_NUM_PROC])[:2] main_proc.proc_control.spawn_many(int(N), kwargs={"queue": queue, "flow": "simple_queue_processor"}) main_proc.start_rpc_server()
def main(args=None): args = parse_args(args) main_proc = rpc_server.MainProcess() config = {} # load default configuration from file for path in (args.config_file, 'config.yaml'): if path and os.path.exists(path): config = read_config(path) break process_config(config) # allow overwritting any configuration setting via env vars for k, v in os.environ.items(): if k.startswith('WORKER_'): config[k.replace("WORKER_", "").replace("_", ".").lower()] = v # make zmon worker compatible with old redis config vars if 'redis.host' in config: port = config.get('redis.port', 6379) config.update( {"redis.servers": '{}:{}'.format(config["redis.host"], port)}) # save config in our settings module settings.set_workers_log_level(config.get('loglevel', 'INFO')) settings.set_external_config(config) settings.set_rpc_server_port(config.get('server.port')) logging.config.dictConfig(settings.RPC_SERVER_CONF['LOGGING']) logger = logging.getLogger(__name__) # start the process controller main_proc.start_proc_control() # start web server process under supervision main_proc.proc_control.spawn_process( target=start_web, kwargs=dict( listen_on=config.get('webserver.listen_on', '0.0.0.0'), port=int(config.get('webserver.port', '8080')), log_conf=None, threaded=True, rpc_url='http://{host}:{port}{path}'.format( host='localhost', port=config.get('server.port'), path=settings.RPC_SERVER_CONF['RPC_PATH']), ), flags=MONITOR_RESTART, # web server will be restarted if dies ) # init the plugin manager plugin_manager.init_plugin_manager() # load external plugins (should be run only once) plugin_manager.collect_plugins(global_config=config, load_builtins=True, load_env=True) # start worker processes per queue according to the config queues = config['zmon.queues'] for qn in queues.split(','): queue, N = (qn.rsplit('/', 1) + [DEFAULT_NUM_PROC])[:2] main_proc.proc_control.spawn_many( int(N), kwargs={ 'queue': queue, 'flow': 'simple_queue_processor', 'tracer': config.get('opentracing.tracer'), 'tracer_tags': { 'team': config.get('team', 'UNKNOWN'), 'account': config.get('account', 'UNKNOWN'), 'region': config.get('region', 'UNKNOWN'), }, }, flags=MONITOR_RESTART | MONITOR_KILL_REQ | MONITOR_PING) if not args.no_rpc: try: main_proc.start_rpc_server() except (KeyboardInterrupt, SystemExit): logger.info('RPC server stopped. Exiting main') return main_proc
def main(args=None): args = parse_args(args) main_proc = rpc_server.MainProcess() config = {} # load default configuration from file for path in (args.config_file, 'config.yaml'): if path and os.path.exists(path): config = read_config(path) break process_config(config) # allow overwritting any configuration setting via env vars for k, v in os.environ.items(): if k.startswith('WORKER_'): config[k.replace("WORKER_", "").replace("_", ".").lower()] = v # make zmon worker compatible with old redis config vars if 'redis.host' in config: port = config.get('redis.port', 6379) config.update({"redis.servers": '{}:{}'.format(config["redis.host"], port)}) # save config in our settings module settings.set_workers_log_level(config.get('loglevel', 'INFO')) settings.set_external_config(config) settings.set_rpc_server_port(config.get('server.port')) logging.config.dictConfig(settings.RPC_SERVER_CONF['LOGGING']) logger = logging.getLogger(__name__) # start the process controller main_proc.start_proc_control() # start worker processes per queue according to the config queues = config['zmon.queues'] for qn in queues.split(','): queue, N = (qn.rsplit('/', 1) + [DEFAULT_NUM_PROC])[:2] main_proc.proc_control.spawn_many(int(N), kwargs={"queue": queue, "flow": "simple_queue_processor"}, flags=MONITOR_RESTART | MONITOR_KILL_REQ | MONITOR_PING) # start web server process under supervision main_proc.proc_control.spawn_process( target=start_web, kwargs=dict( listen_on=config.get('webserver.listen_on', '0.0.0.0'), port=int(config.get('webserver.port', '8080')), log_conf=None, threaded=True, rpc_url='http://{host}:{port}{path}'.format(host='localhost', port=config.get('server.port'), path=settings.RPC_SERVER_CONF['RPC_PATH']), ), flags=MONITOR_RESTART, # web server will be restarted if dies ) if not args.no_rpc: try: main_proc.start_rpc_server() except (KeyboardInterrupt, SystemExit): logger.info('RPC server stopped. Exiting main') return main_proc