From e204cc74226b02c83e343408551a97b4befafe18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 2 May 2019 15:07:13 +0200 Subject: [PATCH 1/3] Make event_handler_main shutdown gracefully on SIGTERM and SIGINT --- solvable/src/event_handler_main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/solvable/src/event_handler_main.py b/solvable/src/event_handler_main.py index 9ff99e5..a4f231a 100644 --- a/solvable/src/event_handler_main.py +++ b/solvable/src/event_handler_main.py @@ -1,9 +1,10 @@ from ast import literal_eval from functools import partial +from signal import signal, SIGTERM, SIGINT from tornado.ioloop import IOLoop -from tfw import YamlFSM, FSMAwareEventHandler +from tfw import YamlFSM, FSMAwareEventHandler, EventHandlerBase from tfw.components import IdeEventHandler, TerminalEventHandler from tfw.components import ProcessManagingEventHandler, BashMonitor from tfw.components import TerminalCommands, LogMonitoringEventHandler @@ -136,9 +137,12 @@ if __name__ == '__main__': # Example terminal command callback terminal.historymonitor.subscribe_callback(cenator) - try: - IOLoop.instance().start() - finally: - eventhandlers = {fsm, ide, terminal, processmanager, logmonitor, message_fsm_steps} - for eh in eventhandlers: + event_handlers = EventHandlerBase.get_local_instances() + def cleanup(sig, frame): + for eh in event_handlers: eh.cleanup() + exit(0) + signal(SIGTERM, cleanup) + signal(SIGINT, cleanup) + + IOLoop.instance().start() From 31d8161379fd03afade3826b1ffcaf914d9ce996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Thu, 2 May 2019 15:59:20 +0200 Subject: [PATCH 2/3] Add example process with PipeIO event handlers --- solvable/src/pipe_io_main.py | 24 ++++++++++++++++++++++++ solvable/supervisor/pipe_io_main.conf | 4 ++++ 2 files changed, 28 insertions(+) create mode 100644 solvable/src/pipe_io_main.py create mode 100644 solvable/supervisor/pipe_io_main.conf diff --git a/solvable/src/pipe_io_main.py b/solvable/src/pipe_io_main.py new file mode 100644 index 0000000..e0b0f83 --- /dev/null +++ b/solvable/src/pipe_io_main.py @@ -0,0 +1,24 @@ +from signal import signal, SIGTERM, SIGINT + +from tornado.ioloop import IOLoop + +from tfw import EventHandlerBase +from tfw.components import PipeIOEventHandler + + +if __name__ == '__main__': + ide_pipeio = PipeIOEventHandler( + 'ide', + '/tmp/ide_send', + '/tmp/ide_recv' + ) + + event_handlers = EventHandlerBase.get_local_instances() + def cleanup(sig, frame): + for eh in event_handlers: + eh.cleanup() + exit(0) + signal(SIGTERM, cleanup) + signal(SIGINT, cleanup) + + IOLoop.instance().start() diff --git a/solvable/supervisor/pipe_io_main.conf b/solvable/supervisor/pipe_io_main.conf new file mode 100644 index 0000000..bdf8a1a --- /dev/null +++ b/solvable/supervisor/pipe_io_main.conf @@ -0,0 +1,4 @@ +[program:pipe_io_main] +user=root +directory=%(ENV_TFW_EHMAIN_DIR)s +command=python3 pipe_io_main.py From fe49e61f82b1396cf9ed4b6d08056c7fc1e7cba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sun, 5 May 2019 21:29:39 +0200 Subject: [PATCH 3/3] Generalize pipeio by subscribing to all keys in pipe_io_main --- solvable/src/pipe_io_main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/solvable/src/pipe_io_main.py b/solvable/src/pipe_io_main.py index e0b0f83..26e7349 100644 --- a/solvable/src/pipe_io_main.py +++ b/solvable/src/pipe_io_main.py @@ -7,10 +7,10 @@ from tfw.components import PipeIOEventHandler if __name__ == '__main__': - ide_pipeio = PipeIOEventHandler( - 'ide', - '/tmp/ide_send', - '/tmp/ide_recv' + pipe_io = PipeIOEventHandler( + '', + '/tmp/tfw_send', + '/tmp/tfw_recv' ) event_handlers = EventHandlerBase.get_local_instances()