From 1b01d9b3244895bb717f32f2e5b7658014d203eb Mon Sep 17 00:00:00 2001 From: Siarhei Siniak Date: Sat, 3 Sep 2022 16:01:07 +0300 Subject: [PATCH] [~] Refactor --- d1/dynu_update.py | 15 +++++++++++++++ docker/dynu/Dockerfile | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/d1/dynu_update.py b/d1/dynu_update.py index 25d8960..335d78b 100644 --- a/d1/dynu_update.py +++ b/d1/dynu_update.py @@ -1,3 +1,4 @@ +import signal import multiprocessing import time import traceback @@ -89,6 +90,20 @@ def service(): need_wait = False last_disabled = False + def handle_exit(*argv): + sys.stderr.write('got %s\n' % pprint.pformat(argv)) + sys.stderr.flush() + raise KeyboardInterrupt + + for current_signal in [ + signal.SIGINT, + signal.SIGTERM + ]: + signal.signal( + current_signal, + handle_exit, + ) + while True: try: if need_wait: diff --git a/docker/dynu/Dockerfile b/docker/dynu/Dockerfile index b41b322..25e0398 100644 --- a/docker/dynu/Dockerfile +++ b/docker/dynu/Dockerfile @@ -3,4 +3,5 @@ WORKDIR /app RUN pip3 install requests -ENTRYPOINT exec python3 d1/dynu_update tmp/cache/dynu.auth.json ngrok +CMD ["-c", "exec python3 d1/dynu_update.py tmp/cache/dynu.auth.json ngrok"] +ENTRYPOINT ["/bin/bash"]