diff --git a/cloudAPI/cloudManager.py b/cloudAPI/cloudManager.py index 6bbca1e74..b2850f8cd 100755 --- a/cloudAPI/cloudManager.py +++ b/cloudAPI/cloudManager.py @@ -2673,3 +2673,19 @@ class CloudManager: final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)} final_json = json.dumps(final_dic) return HttpResponse(final_json) + + def DetachCluster(self): + try: + + type = self.data['type'] + + execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function %s --type %s" % ('DetachCluster', type) + ProcessUtilities.popenExecutioner(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 1a57cb951..5a66dc7cd 100755 --- a/cloudAPI/views.py +++ b/cloudAPI/views.py @@ -37,6 +37,8 @@ def router(request): return cm.verifyLogin(request)[1] elif controller == 'RunServerLevelEmailChecks': return cm.RunServerLevelEmailChecks() + elif controller == 'DetachCluster': + return cm.DetachCluster() elif controller == 'ReadReport': return cm.ReadReport() elif controller == 'ResetEmailConfigurations': diff --git a/plogical/ClusterManager.py b/plogical/ClusterManager.py new file mode 100644 index 000000000..053979703 --- /dev/null +++ b/plogical/ClusterManager.py @@ -0,0 +1,79 @@ +import json +import os.path +import sys +import argparse +import requests +from plogical.processUtilities import ProcessUtilities + +sys.path.append('/usr/local/CyberCP') +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "CyberCP.settings") + +class ClusterManager: + + LogURL = "http://cloud.cyberpanel.net:8000/HighAvailability/RecvData" + ClusterFile = '/home/cyberpanel/cluster' + + def __init__(self): + ## + ipFile = "/etc/cyberpanel/machineIP" + f = open(ipFile) + ipData = f.read() + self.ipAddress = ipData.split('\n', 1)[0] + ## + self.config = json.loads(open(ClusterManager.ClusterFile, 'r').read()) + + + def PostStatus(self): + finalData = json.dumps(self.config) + resp = requests.post(ClusterManager.LogURL, data=finalData, verify=False) + print (resp.text) + + def FetchMySQLConfigFile(self): + + if ProcessUtilities.decideDistro() == ProcessUtilities.centos: + return '/etc/mysql/conf.d/cluster.cnf' + else: + return '/etc/mysql/conf.d/cluster.cnf' + + def DetechFromCluster(self, type): + try: + command = 'rm -rf %s' % (self.FetchMySQLConfigFile()) + ProcessUtilities.normalExecutioner(command) + + command = 'systemctl stop mysql' + ProcessUtilities.normalExecutioner(command) + + command = 'systemctl restart mysql' + ProcessUtilities.executioner(command) + + if type == 'Child': + self.config['failoverServerMessage'] = 'Successfully detached. [200]' + self.PostStatus() + else: + self.config['masterServerMessage'] = 'Successfully detached. [200]' + self.PostStatus() + + except BaseException as msg: + if type == 'Child': + self.config['failoverServerMessage'] = 'Failed to detach, error %s [404].' % (str(msg)) + self.PostStatus() + else: + self.config['masterServerMessage'] = 'Failed to detach, error %s [404].' % (str(msg)) + self.PostStatus() + + +def main(): + parser = argparse.ArgumentParser(description='CyberPanel Installer') + parser.add_argument('--function', help='Function to run.') + parser.add_argument('--type', help='Type of detach.') + + args = parser.parse_args() + + uc = ClusterManager() + + if args.function == 'DetachCluster': + uc.DetechFromCluster() + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/plogical/IncScheduler.py b/plogical/IncScheduler.py index 734c96a58..0a138b976 100644 --- a/plogical/IncScheduler.py +++ b/plogical/IncScheduler.py @@ -488,25 +488,29 @@ Automatic backup failed for %s on %s. if jobConfig[IncScheduler.frequency] == type: ### Check if an old job prematurely killed, then start from there. - try: - oldJobContinue = 1 - pid = jobConfig['pid'] - stuckDomain = jobConfig['website'] - finalPath = jobConfig['finalPath'] - jobConfig['pid'] = str(os.getpid()) + # try: + # oldJobContinue = 1 + # pid = jobConfig['pid'] + # stuckDomain = jobConfig['website'] + # finalPath = jobConfig['finalPath'] + # jobConfig['pid'] = str(os.getpid()) + # + # command = 'ps aux' + # result = ProcessUtilities.outputExecutioner(command) + # + # if result.find(pid) > -1 and result.find('IncScheduler.py') > -1: + # quit(1) + # + # + # except: + # ### Save some important info in backup config + # oldJobContinue = 0 + # jobConfig['pid'] = str(os.getpid()) + # jobConfig['finalPath'] = finalPath - command = 'ps aux' - result = ProcessUtilities.outputExecutioner(command) - - if result.find(pid) > -1 and result.find('IncScheduler.py') > -1: - quit(1) - - - except: - ### Save some important info in backup config - oldJobContinue = 0 - jobConfig['pid'] = str(os.getpid()) - jobConfig['finalPath'] = finalPath + oldJobContinue = 0 + jobConfig['pid'] = str(os.getpid()) + jobConfig['finalPath'] = finalPath NormalBackupJobLogs.objects.filter(owner=backupjob).delete() NormalBackupJobLogs(owner=backupjob, status=backupSchedule.INFO,