Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed lock file upon receiving interrupt signals #72

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading