Skip to content

Commit

Permalink
Added a check to prevent conversion if Amavis antivirus is installed …
Browse files Browse the repository at this point in the history
…and there is not enough RAM
  • Loading branch information
Mikhail Sandakov committed Aug 2, 2024
1 parent f22926f commit 20343c0
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion pleskdistup/actions/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
import os
import pwd
import shutil
import sys
import typing

from pleskdistup.common import action, dist, files, plesk, log, systemd, util
from pleskdistup.common import action, dist, files, packages, plesk, log, systemd, util


class DisableGrafana(action.ActiveAction):
Expand Down Expand Up @@ -253,3 +254,32 @@ def _do_check(self) -> bool:
return not self.installed_violations and not self.not_installed_violations
except plesk.PleskDatabaseIsDown:
return True


class AssertEnoughRamForAmavis(action.CheckAction):
required_ram: int
amavis_upgrade_allowed: bool

def __init__(self, required_ram: int, amavis_upgrade_allowed: bool):
self.name = "asserting enough RAM for Amavis"
self.required_ram = required_ram
self.amavis_upgrade_allowed = amavis_upgrade_allowed
self.description = f"""You have Amavis antivirus installed. It needs at least {required_ram / 1073741824} GB of RAM to work properly on the target OS.
\tIf you don’t have enough RAM, Amavis might crash or cause your system to stop working.
\tIf you accept this risk, you can proceed by running `{os.path.basename(sys.argv[0])} --amavis-upgrade-allowed`.
\tAlternatively, you can remove Amavis antivirus to proceed with the conversion.
"""

def _get_available_ram(self) -> int:
with open('/proc/meminfo', 'r') as meminfo:
for line in meminfo:
if line.startswith('MemAvailable:'):
# We got data in KB, so we need to convert it to bytes
return int(line.split()[1]) * 1024
return 0

def _do_check(self) -> bool:
# Amavis consumes a lot of RAM on AlmaLinux 8, which for example causes hangs on t2.micro instances
# Therefore, it's advisable to inform users about potential issues beforehand
# If you add support for other OSes it worth to check the RAM requirements for amavis on them
return not packages.is_package_installed("amavis") or self._get_available_ram() > self.required_ram or self.amavis_upgrade_allowed

0 comments on commit 20343c0

Please sign in to comment.