Skip to content

Commit

Permalink
fixup! Verify that the Plesk database is functioning before attemptin…
Browse files Browse the repository at this point in the history
…g to collaborate on any Plesk extensions
  • Loading branch information
Mikhail Sandakov committed Jul 24, 2024
1 parent 621c083 commit c72d83f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pleskdistup/actions/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,14 @@ def _is_required(self) -> bool:
return self.ext_name in dict(plesk.list_installed_extensions())
except plesk.PleskDatabaseIsDown:
# If database is not ready we will not be able to uninstall the extension anyway
log.warn("Mark the Tuxcare ELS extension uninstallation as unnecessary because the Plesk database isn't running")
return False

def _prepare_action(self) -> action.ActionResult:
try:
plesk.uninstall_extension(self.ext_name)
except plesk.PleskDatabaseIsDown:
log.warn("Removing TuxCare ELS extension called when database is already down")
log.warn("Removing TuxCare ELS extension called when Plesk database is already down")
return action.ActionResult()

def _post_action(self) -> action.ActionResult:
Expand All @@ -166,7 +167,7 @@ def _revert_action(self) -> action.ActionResult:
try:
plesk.install_extension(self.ext_name)
except plesk.PleskDatabaseIsDown:
log.warn("Re-installing TuxCare ELS extension called when database is still down")
log.warn("Re-installing TuxCare ELS extension called when Plesk database is still down")
return action.ActionResult()

def estimate_prepare_time(self) -> int:
Expand Down
8 changes: 4 additions & 4 deletions pleskdistup/common/src/plesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def remove_conversion_flag(status_flag_path: str) -> None:

def list_installed_extensions() -> typing.List[typing.Tuple[str, str]]:
if not is_plesk_database_ready():
raise PleskDatabaseIsDown("on retrieving installed extensions")
raise PleskDatabaseIsDown("retrieving installed extensions")

ext_info = subprocess.check_output(["/usr/sbin/plesk", "bin", "extension", "--list"], universal_newlines=True).splitlines()
res: typing.List[typing.Tuple[str, str]] = []
Expand All @@ -128,14 +128,14 @@ def list_installed_extensions() -> typing.List[typing.Tuple[str, str]]:

def install_extension(name: str) -> None:
if not is_plesk_database_ready():
raise PleskDatabaseIsDown(f"on extension {name!r} installation")
raise PleskDatabaseIsDown(f"extension {name!r} installation")

util.logged_check_call(["/usr/sbin/plesk", "bin", "extension", "--install", name])


def uninstall_extension(name: str) -> None:
if not is_plesk_database_ready():
raise PleskDatabaseIsDown(f"on extension {name!r} uninstallation")
raise PleskDatabaseIsDown(f"extension {name!r} uninstallation")

util.logged_check_call(["/usr/sbin/plesk", "bin", "extension", "--uninstall", name])

Expand Down Expand Up @@ -209,8 +209,8 @@ def list_installed_components() -> typing.Dict[str, PleskComponent]:

class PleskDatabaseIsDown(Exception):
def __init__(self, message: str = ""):
super().__init__()
self.message = f"Plesk database is not ready at: {message}"
super().__init__(self.message)


def is_plesk_database_ready() -> bool:
Expand Down

0 comments on commit c72d83f

Please sign in to comment.