diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index eadb8b88d..f2ccd09fb 100755 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -2929,3 +2929,19 @@ class CloudManager: final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) + + def DebugCluster(self): + try: + + type = self.data['type'] + + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function %s --type %s" % ('DebugCluster', type) + ProcessUtilities.executioner(execPath) + + final_json = json.dumps({'status': 1}) + return HttpResponse(final_json) + + except BaseException as msg: + final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} + final_json = json.dumps(final_dic) + return HttpResponse(final_json) diff --git a/cloudAPI/views.py b/cloudAPI/views.py index 0a61ff061..72c08f0c8 100755 --- a/cloudAPI/views.py +++ b/cloudAPI/views.py @@ -48,6 +48,8 @@ def router(request): return cm.RunServerLevelEmailChecks() elif controller == 'DetachCluster': return cm.DetachCluster() + elif controller == 'DebugCluster': + return cm.DebugCluster() elif controller == 'FetchMasterBootStrapStatus': return cm.FetchMasterBootStrapStatus() elif controller == 'FetchChildBootStrapStatus': diff --git a/plogical/ClusterManager.py b/plogical/ClusterManager.py index 2e71cb776..511c9f6e5 100644 --- a/plogical/ClusterManager.py +++ b/plogical/ClusterManager.py @@ -1,5 +1,7 @@ import json import os.path +import shlex +import subprocess import sys import argparse import django @@ -329,6 +331,30 @@ password=%s""" % (rootdbpassword, rootdbpassword) except BaseException as msg: self.PostStatus('Failed to ping cloud for online status, error %s [404].' % (str(msg))) + def DebugCluster(self): + try: + + if os.path.exists(ClusterManager.ClusterFile): + self.PostStatus('Cluster config file exixts.') + else: + self.PostStatus('Cluster config file does not exists. [404]') + + if os.path.exists(self.FetchMySQLConfigFile()): + self.PostStatus('MySQL Cluster file exists.') + else: + self.PostStatus('MySQL Cluster file does not exists. [404]') + + command = 'systemctl status mysql' + result = subprocess.check_output(shlex.split(command)).decode("utf-8") + + if result.find("active (running)") > -1: + self.PostStatus('MySQL server is running.') + else: + self.PostStatus('MySQL server is down. [404]') + + except BaseException as msg: + self.PostStatus('Failed to debug cluster, error %s [404].' % (str(msg))) + def main(): parser = argparse.ArgumentParser(description='CyberPanel Installer') @@ -353,6 +379,8 @@ def main(): uc.SyncNow() elif args.function == 'PingNow': uc.PingNow() + elif args.function == 'DebugCluster': + uc.DebugCluster() if __name__ == "__main__": diff --git a/plogical/processUtilities.py b/plogical/processUtilities.py index ecdf55cb5..e8caa6383 100755 --- a/plogical/processUtilities.py +++ b/plogical/processUtilities.py @@ -274,6 +274,7 @@ class ProcessUtilities(multi.Thread): @staticmethod def outputExecutioner(command, user=None, shell = None, dir = None): try: + if getpass.getuser() == 'root': if os.path.exists(ProcessUtilities.debugPath): logging.writeToFile(command) @@ -320,6 +321,7 @@ class ProcessUtilities(multi.Thread): @staticmethod def BuildCommand(path, functionName, parameters): + execPath = "/usr/local/CyberCP/bin/python %s %s " % (path, functionName) for key, value in parameters.items(): execPath = execPath + ' --%s %s' % (key, value) diff --git a/pluginHolder/views.py b/pluginHolder/views.py index 44e564fc3..25ecc2b6a 100755 --- a/pluginHolder/views.py +++ b/pluginHolder/views.py @@ -1,14 +1,11 @@ # -*- coding: utf-8 -*- - - from django.shortcuts import render from plogical.mailUtilities import mailUtilities import os from xml.etree import ElementTree - +from plogical.httpProc import httpProc def installed(request): - mailUtilities.checkHome() pluginPath = '/home/cyberpanel/plugins' pluginList = [] @@ -26,5 +23,6 @@ def installed(request): pluginList.append(data) - - return render(request, 'pluginHolder/plugins.html',{'plugins': pluginList}) + proc = httpProc(request, 'pluginHolder/plugins.html', + {'plugins': pluginList}, 'admin') + return proc.render()