Skip to content

Commit

Permalink
Move assing signals handler to a separate function
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Sandakov committed Oct 9, 2024
1 parent a60561e commit 3baa2bc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pleskdistup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ def exit_signal_handler(signum, frame):
return exit_signal_handler


def assign_killing_signals(handler: typing.Callable[[int, typing.Any], None]) -> None:
for signum in (signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGABRT):
signal.signal(signum, handler)


DESC_MESSAGE = """Use this utility to dist-upgrade your server with Plesk.
The utility writes a log to the file specified by --log-file. If there are any issues, you can find more information in the log file.
Expand Down Expand Up @@ -425,9 +430,7 @@ def main():
options.help = False

# signals handler initialization
exit_signal_handler = create_exit_signal_handler(util_name)
for signum in (signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGABRT):
signal.signal(signum, exit_signal_handler)
assign_killing_signals(create_exit_signal_handler(util_name))

# Configure locale to avoid problems on systems where LANG or LC_CTYPE changed,
# while files on the system still has utf-8 encoding
Expand Down Expand Up @@ -617,9 +620,7 @@ def main():

# After lock there's no need to manage signals in such a detailed manner
# Simply log the reason for not rebooting
exit_signal_handler = create_exit_signal_handler(util_name)
for signum in (signal.SIGINT, signal.SIGTERM, signal.SIGHUP, signal.SIGABRT):
signal.signal(signum, lambda signum, frame: log.info(f"Received signal {signum}, going to exit..."))
assign_killing_signals(lambda signum, frame: log.info(f"Received signal {signum}, going to exit..."))

if not options.no_reboot and convert_result.reboot_requested:
log.info("Going to reboot the system")
Expand Down

0 comments on commit 3baa2bc

Please sign in to comment.