def main(): # Check command line options try: opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['help', 'config=']) except getopt.GetoptError: usage(1) cfg = None for opt, arg in opts: if opt in ("-h", "--help"): usage() if opt in ('-c', '--config'): cfg = arg break # Make sure we got only one command if len(args) > 1: usage(2) try: config.update_configuration(cfg) except ValueError as e: print(str(e)) sys.exit(4) # Set signal handler signal.signal(signal.SIGINT, sigint_handler) signal.signal(signal.SIGTERM, sigterm_handler) # Get the command with `run` as default cmd = (args + ['run'])[0] if cmd == 'run': # ensure database is created first get_session().close() run_all(schedule, capture, ingest, agentstate) elif cmd == 'all': get_session().close() signal.signal(signal.SIGINT, signal.default_int_handler) multiprocessing.Process( target=ui.app.run, kwargs={'threaded': False} ).start() run_all(schedule, capture, ingest, agentstate) elif cmd == 'schedule': schedule.run() elif cmd == 'capture': capture.run() elif cmd == 'ingest': ingest.run() elif cmd == 'agentstate': agentstate.run() elif cmd == 'ui': signal.signal(signal.SIGINT, signal.default_int_handler) ui.app.run(threaded=False) else: # Invalid command usage(3)
def test_run(self): capture.terminate = terminate_fn(1) capture.run()
def main(): # Probe for configuration file location cfg = '/etc/pyca.conf' if not os.path.isfile(cfg): cfg = './etc/pyca.conf' # Check command line options try: opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['help', 'config=']) except getopt.GetoptError: usage(1) for opt, arg in opts: if opt in ("-h", "--help"): usage() if opt in ('-c', '--config'): cfg = arg break # Make sure we got only one command if len(args) > 1: usage(2) try: config.update_configuration(cfg) except ValueError as e: print(str(e)) sys.exit(4) # Initialize logger handlers = [] conf = config.config() if conf['logging']['syslog']: handlers.append(logging.handlers.SysLogHandler(address='/dev/log')) if conf['logging']['stderr']: handlers.append(logging.StreamHandler(sys.stderr)) logger = logging.getLogger('') for h in handlers: h.setFormatter(logging.Formatter( '[%(name)s:%(lineno)s:%(funcName)s()] %(message)s')) logger.addHandler(h) logger.setLevel(conf['logging']['level'].upper()) # Set signal handler signal.signal(signal.SIGINT, sigint_handler) signal.signal(signal.SIGTERM, sigterm_handler) # Get the command with `run` as default cmd = (args + ['run'])[0] if cmd == 'run': run_all(schedule, capture, ingest, agentstate) elif cmd == 'schedule': schedule.run() elif cmd == 'capture': capture.run() elif cmd == 'ingest': ingest.run() elif cmd == 'agentstate': agentstate.run() elif cmd == 'ui': signal.signal(signal.SIGINT, signal.default_int_handler) ui.app.run() else: # Invalid command usage(3)