Skip to content

Commit

Permalink
Merge pull request #72 from plesk/free-lock-on-signals
Browse files Browse the repository at this point in the history
Removed lock file upon receiving interrupt signals
  • Loading branch information
SandakovMM authored Sep 11, 2024
2 parents 1d9c1cf + 8959277 commit cd4724a
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 cd4724a

Please sign in to comment.