Skip to content

Commit

Permalink
Invoke the exit function to delete the lock file and release resource…
Browse files Browse the repository at this point in the history
…s upon receiving signals
  • Loading branch information
Mikhail Sandakov committed Sep 11, 2024
1 parent 7a13418 commit 8959277
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pleskdistup/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import locale
import logging
import os
import signal
import sys
import time
import traceback
Expand Down Expand Up @@ -317,6 +318,12 @@ def try_lock(lock_file: PathType) -> typing.Generator[bool, None, None]:
log.warn(f"Failed to remove lockfile {lock_file!r}: {ex}")


def exit_signal_handler(signum, frame):
# exit will trigger blocks finalization, so lockfile will be removed
log.info(f"Received signal {signum}, going to exit...")
sys.exit(1)


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 @@ -406,6 +413,10 @@ def main():
else:
options.help = False

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

# Configure locale to avoid problems on systems where LANG or LC_CTYPE changed,
# while files on the system still has utf-8 encoding
# We should do it before initializing logger to make sure utf-8 symbols will be
Expand Down

0 comments on commit 8959277

Please sign in to comment.