From 95e38e70f3fe8b036ce382cc972339645d9f4bc9 Mon Sep 17 00:00:00 2001 From: master3395 Date: Tue, 31 Mar 2026 20:41:00 +0200 Subject: [PATCH] Add RabbitMQ support to Manage Applications and lifecycle flows. Wire RabbitMQ into app management UI/actions, optional fresh-install flag handling, and upgrade-safe marker/service reconciliation so new installs and upgrades can expose it reliably. --- install/install.py | 29 ++++++++ manageServices/serviceManager.py | 70 +++++++++++++++++++ .../static/manageServices/images/rabbitmq.svg | 6 ++ .../manageServices/applications.html | 2 + manageServices/views.py | 18 +++++ plogical/upgrade.py | 31 ++++++++ 6 files changed, 156 insertions(+) create mode 100644 manageServices/static/manageServices/images/rabbitmq.svg diff --git a/install/install.py b/install/install.py index f66fc189b..897af0aea 100644 --- a/install/install.py +++ b/install/install.py @@ -6250,6 +6250,31 @@ vmail command = 'systemctl enable redis' preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) + def installRabbitMQ(self): + rabbitMQMarker = '/home/cyberpanel/rabbitmq' + + # Keep optional installer idempotent for reruns/retries. + if os.path.exists(rabbitMQMarker): + preFlightsChecks.stdOut("RabbitMQ marker already exists, skipping optional RabbitMQ installation.") + return + + if self.distro == ubuntu or self.distro == debian12: + command = 'DEBIAN_FRONTEND=noninteractive apt install rabbitmq-server -y' + elif self.distro == centos: + command = 'yum install rabbitmq-server -y' + else: + command = 'dnf install rabbitmq-server -y' + preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) + + command = 'systemctl enable rabbitmq-server' + preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) + + command = 'systemctl start rabbitmq-server' + preFlightsChecks.call(command, self.distro, command, command, 1, 0, os.EX_OSERR) + + writeToFile = open(rabbitMQMarker, 'w') + writeToFile.close() + def disablePackegeUpdates(self): if self.distro == centos: mainConfFile = '/etc/yum.conf' @@ -6752,6 +6777,7 @@ def main(): parser.add_argument('--serial', help='Install LS Ent or OpenLiteSpeed') parser.add_argument('--port', help='LSCPD Port') parser.add_argument('--redis', help='vHosts on Redis - Requires LiteSpeed Enterprise') + parser.add_argument('--rabbitmq', help='Enable optional RabbitMQ installation.') parser.add_argument('--remotemysql', help='Opt to choose local or remote MySQL') parser.add_argument('--mysqlhost', help='MySQL host if remote is chosen.') parser.add_argument('--mysqldb', help='MySQL DB if remote is chosen.') @@ -7020,6 +7046,9 @@ def main(): if args.redis is not None: checks.installRedis() + if args.rabbitmq is not None and str(args.rabbitmq).upper() == 'ON': + checks.installRabbitMQ() + if args.powerdns is not None: checks.enableDisableDNS(args.powerdns.lower()) else: diff --git a/manageServices/serviceManager.py b/manageServices/serviceManager.py index 0476b3b02..79109638e 100644 --- a/manageServices/serviceManager.py +++ b/manageServices/serviceManager.py @@ -304,6 +304,72 @@ type=rpm-md "Redis successfully removed.[200]\n", 1) return 0 + @staticmethod + def InstallRabbitMQ(): + statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w') + + try: + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + command = 'yum install rabbitmq-server -y' + ServerStatusUtil.executioner(command, statusFile) + else: + command = 'DEBIAN_FRONTEND=noninteractive apt-get install rabbitmq-server -y' + ServerStatusUtil.executioner(command, statusFile) + + command = 'systemctl enable rabbitmq-server' + ServerStatusUtil.executioner(command, statusFile) + + command = 'systemctl start rabbitmq-server' + ServerStatusUtil.executioner(command, statusFile) + + command = 'touch /home/cyberpanel/rabbitmq' + ServerStatusUtil.executioner(command, statusFile) + + logging.CyberCPLogFileWriter.statusWriter( + ServerStatusUtil.lswsInstallStatusPath, + "RabbitMQ successfully installed.[200]\n", 1 + ) + return 0 + except BaseException as msg: + logging.CyberCPLogFileWriter.statusWriter( + ServerStatusUtil.lswsInstallStatusPath, + "RabbitMQ installation failed: %s.[500]\n" % (str(msg)), 0 + ) + return 1 + + @staticmethod + def RemoveRabbitMQ(): + statusFile = open(ServerStatusUtil.lswsInstallStatusPath, 'w') + + try: + command = 'systemctl stop rabbitmq-server' + ServerStatusUtil.executioner(command, statusFile) + + command = 'systemctl disable rabbitmq-server' + ServerStatusUtil.executioner(command, statusFile) + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos or ProcessUtilities.decideDistro() == ProcessUtilities.cent8: + command = 'yum erase rabbitmq-server -y' + ServerStatusUtil.executioner(command, statusFile) + else: + command = 'DEBIAN_FRONTEND=noninteractive apt-get remove rabbitmq-server -y' + ServerStatusUtil.executioner(command, statusFile) + + command = 'rm -f /home/cyberpanel/rabbitmq' + ServerStatusUtil.executioner(command, statusFile) + + logging.CyberCPLogFileWriter.statusWriter( + ServerStatusUtil.lswsInstallStatusPath, + "RabbitMQ successfully removed.[200]\n", 1 + ) + return 0 + except BaseException as msg: + logging.CyberCPLogFileWriter.statusWriter( + ServerStatusUtil.lswsInstallStatusPath, + "RabbitMQ removal failed: %s.[500]\n" % (str(msg)), 0 + ) + return 1 + def main(): parser = argparse.ArgumentParser(description='CyberPanel Application Manager') @@ -320,6 +386,10 @@ def main(): ServiceManager.InstallRedis() elif args["function"] == "RemoveRedis": ServiceManager.RemoveRedis() + elif args["function"] == "InstallRabbitMQ": + ServiceManager.InstallRabbitMQ() + elif args["function"] == "RemoveRabbitMQ": + ServiceManager.RemoveRabbitMQ() diff --git a/manageServices/static/manageServices/images/rabbitmq.svg b/manageServices/static/manageServices/images/rabbitmq.svg new file mode 100644 index 000000000..72a526816 --- /dev/null +++ b/manageServices/static/manageServices/images/rabbitmq.svg @@ -0,0 +1,6 @@ + +RabbitMQ +RabbitMQ application icon + + + diff --git a/manageServices/templates/manageServices/applications.html b/manageServices/templates/manageServices/applications.html index 2420c68e2..de44559f4 100644 --- a/manageServices/templates/manageServices/applications.html +++ b/manageServices/templates/manageServices/applications.html @@ -405,6 +405,8 @@ {% trans "A distributed, RESTful search and analytics engine capable of addressing a growing number of use cases." %} {% elif service.name == 'Redis' %} {% trans "An in-memory data structure store, used as a database, cache, and message broker." %} + {% elif service.name == 'RabbitMQ' %} + {% trans "A reliable message broker for asynchronous processing, queueing, and service-to-service communication." %} {% else %} {% trans "Powerful application for your server infrastructure." %} {% endif %} diff --git a/manageServices/views.py b/manageServices/views.py index 65aeb0fe8..67f3c79c3 100644 --- a/manageServices/views.py +++ b/manageServices/views.py @@ -276,6 +276,7 @@ def manageApplications(request): esPath = '/home/cyberpanel/elasticsearch' rPath = '/home/cyberpanel/redis' + rmqPath = '/home/cyberpanel/rabbitmq' if os.path.exists(esPath): installed = 'Installed' @@ -287,12 +288,20 @@ def manageApplications(request): else: rInstalled = 'Not-Installed' + if os.path.exists(rmqPath): + rmqInstalled = 'Installed' + else: + rmqInstalled = 'Not-Installed' + elasticSearch = {'image': '/static/manageServices/images/elastic-search.png', 'name': 'Elasticsearch', 'installed': installed} redis = {'image': '/static/manageServices/images/redis.png', 'name': 'Redis', 'installed': rInstalled} + rabbitmq = {'image': '/static/manageServices/images/rabbitmq.svg', 'name': 'RabbitMQ', + 'installed': rmqInstalled} services.append(elasticSearch) services.append(redis) + services.append(rabbitmq) proc = httpProc(request, 'manageServices/applications.html', {'services': services}, 'admin') @@ -323,6 +332,15 @@ def removeInstall(request): command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/manageServices/serviceManager.py --function InstallRedis' else: command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/manageServices/serviceManager.py --function RemoveRedis' + elif appName == 'RabbitMQ': + if status == 'Installing': + command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/manageServices/serviceManager.py --function InstallRabbitMQ' + else: + command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/manageServices/serviceManager.py --function RemoveRabbitMQ' + else: + data_ret = {'status': 0, 'error_message': 'Unknown application selected.'} + json_data = json.dumps(data_ret) + return HttpResponse(json_data) ProcessUtilities.popenExecutioner(command) data_ret = {'status': 1} diff --git a/plogical/upgrade.py b/plogical/upgrade.py index 8241e1c1f..d2869a2c4 100644 --- a/plogical/upgrade.py +++ b/plogical/upgrade.py @@ -4434,6 +4434,36 @@ class Migration(migrations.Migration): except: pass + @staticmethod + def rabbitMQMigrations(): + marker_path = '/home/cyberpanel/rabbitmq' + rabbitmq_service_files = [ + '/usr/lib/systemd/system/rabbitmq-server.service', + '/lib/systemd/system/rabbitmq-server.service' + ] + rabbitmq_binary_paths = [ + '/usr/sbin/rabbitmq-server', + '/usr/lib/rabbitmq/bin/rabbitmq-server' + ] + + try: + rabbitmq_installed = any(os.path.exists(path) for path in rabbitmq_service_files + rabbitmq_binary_paths) + + if rabbitmq_installed: + if not os.path.exists(marker_path): + writeToFile = open(marker_path, 'w+') + writeToFile.close() + Upgrade.stdOut('RabbitMQ detected during upgrade. Marker file created.', 0) + + Upgrade.executioner('systemctl enable rabbitmq-server', 'Enable RabbitMQ service', 0) + Upgrade.executioner('systemctl start rabbitmq-server', 'Start RabbitMQ service', 0) + else: + if os.path.exists(marker_path): + os.remove(marker_path) + Upgrade.stdOut('RabbitMQ marker removed because service is not installed.', 0) + except BaseException as msg: + Upgrade.stdOut('RabbitMQ migration failed: ' + str(msg), 0) + @staticmethod def backupCriticalFiles(): """Backup all critical configuration files before upgrade""" @@ -6652,6 +6682,7 @@ slowlog = /var/log/php{version}-fpm-slow.log Upgrade.setupWebmail() Upgrade.setupSieve() Upgrade.enableServices() + Upgrade.rabbitMQMigrations() # Apply AlmaLinux 9 fixes before other installations Upgrade.fix_almalinux9_mariadb()