|
|
|
@ -1,17 +1,25 @@
|
|
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
import logging
|
|
|
|
|
import selectors
|
|
|
|
|
import signal
|
|
|
|
|
import socket
|
|
|
|
|
|
|
|
|
|
from . import fieldpoc
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger("fieldpoc.run")
|
|
|
|
|
|
|
|
|
|
ap = argparse.ArgumentParser(prog="fieldpoc")
|
|
|
|
|
ap.add_argument("-c", "--config", dest="config_file_path", default="fieldpoc_config.json", help="Path to the fieldpoc config file")
|
|
|
|
|
ap.add_argument("-e", "--extensions", dest="extensions_file_path", default="fieldpoc_extensions.json", help="Path to the fieldpoc extensions file")
|
|
|
|
|
ap.add_argument('--debug', dest="debug", action='store_true')
|
|
|
|
|
|
|
|
|
|
def run():
|
|
|
|
|
args = ap.parse_args()
|
|
|
|
|
if args.debug:
|
|
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
|
|
|
|
|
|
sel = selectors.DefaultSelector()
|
|
|
|
|
|
|
|
|
|
interrupt_stop_read, interrupt_stop_write = socket.socketpair()
|
|
|
|
@ -22,17 +30,23 @@ def run():
|
|
|
|
|
signal.signal(signal.SIGHUP, lambda signum, frame: interrupt_reload_write.send(b'\0'))
|
|
|
|
|
sel.register(interrupt_reload_read, selectors.EVENT_READ)
|
|
|
|
|
|
|
|
|
|
args = ap.parse_args()
|
|
|
|
|
fp = fieldpoc.FieldPOC(**args.__dict__)
|
|
|
|
|
logger.info("prepared signal handling")
|
|
|
|
|
|
|
|
|
|
fp = fieldpoc.FieldPOC(config_file_path=args.config_file_path, extensions_file_path=args.extensions_file_path)
|
|
|
|
|
fp.run()
|
|
|
|
|
|
|
|
|
|
logger.info("handle signals")
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
for key, mask in sel.select():
|
|
|
|
|
logger.info("incoming signal")
|
|
|
|
|
key.fileobj.recv(1)
|
|
|
|
|
if key.fileobj == interrupt_stop_read:
|
|
|
|
|
logger.info("signal requested service stop")
|
|
|
|
|
fp.queue_all({"type": "stop"})
|
|
|
|
|
exit()
|
|
|
|
|
elif key.fileobj == interrupt_reload_read:
|
|
|
|
|
logger.info("signal requested reload")
|
|
|
|
|
fp.queue_all({"type": "reload"})
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|