mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2025-11-10 15:26:13 +01:00
set up cluster
This commit is contained in:
@@ -13,7 +13,7 @@ import json
|
||||
import threading as multi
|
||||
import time
|
||||
import asyncio
|
||||
|
||||
from plogical.processUtilities import ProcessUtilities
|
||||
|
||||
class SSHServer(multi.Thread):
|
||||
OKGREEN = '\033[92m'
|
||||
@@ -24,7 +24,8 @@ class SSHServer(multi.Thread):
|
||||
@staticmethod
|
||||
def findSSHPort():
|
||||
try:
|
||||
sshData = open('/etc/ssh/sshd_config', 'r').readlines()
|
||||
|
||||
sshData = ProcessUtilities.outputExecutioner('cat /etc/ssh/sshd_config').readlines()
|
||||
|
||||
for items in sshData:
|
||||
if items.find('Port') > -1:
|
||||
|
||||
@@ -2484,11 +2484,14 @@ class CloudManager:
|
||||
fm = FirewallManager()
|
||||
fm.addSSHKey(self.admin.pk, self.data)
|
||||
|
||||
## Create backup path so that file can be sent here later.
|
||||
## Create backup path so that file can be sent here later. If just submitting the key, no need to create backup folder domain.
|
||||
|
||||
try:
|
||||
BackupPath = '/home/cyberpanel/backups/%s' % (self.data['domain'])
|
||||
command = 'mkdir -p %s' % (BackupPath)
|
||||
ProcessUtilities.executioner(command, 'cyberpanel')
|
||||
except:
|
||||
pass
|
||||
|
||||
###
|
||||
|
||||
@@ -2689,3 +2692,23 @@ class CloudManager:
|
||||
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
|
||||
final_json = json.dumps(final_dic)
|
||||
return HttpResponse(final_json)
|
||||
|
||||
def SetupCluster(self):
|
||||
try:
|
||||
|
||||
ClusterConfigPath = '/home/cyberpanel/cluster'
|
||||
writeToFile = open(ClusterConfigPath, 'w')
|
||||
writeToFile.write(json.dumps(self.data))
|
||||
writeToFile.close()
|
||||
|
||||
execPath = "/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function %s --type %s" % (
|
||||
'SetupCluster', 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)
|
||||
|
||||
@@ -39,6 +39,8 @@ def router(request):
|
||||
return cm.RunServerLevelEmailChecks()
|
||||
elif controller == 'DetachCluster':
|
||||
return cm.DetachCluster()
|
||||
elif controller == 'SetupCluster':
|
||||
return cm.SetupCluster()
|
||||
elif controller == 'ReadReport':
|
||||
return cm.ReadReport()
|
||||
elif controller == 'ResetEmailConfigurations':
|
||||
|
||||
@@ -60,6 +60,45 @@ class ClusterManager:
|
||||
self.config['masterServerMessage'] = 'Failed to detach, error %s [404].' % (str(msg))
|
||||
self.PostStatus()
|
||||
|
||||
def SetupCluster(self, type):
|
||||
try:
|
||||
|
||||
ClusterPath = self.FetchMySQLConfigFile()
|
||||
ClusterConfigPath = '/home/cyberpanel/cluster'
|
||||
config = json.loads(open(ClusterConfigPath, 'r').read())
|
||||
|
||||
command = 'systemctl stop mysql'
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
if type == 'Child':
|
||||
|
||||
writeToFile = open(ClusterPath, 'w')
|
||||
writeToFile.write(config['ClusterConfigFailover'])
|
||||
|
||||
command = 'systemctl start mysql'
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
self.config['failoverServerMessage'] = 'Successfully attached to cluster. [200]'
|
||||
self.PostStatus()
|
||||
else:
|
||||
|
||||
writeToFile = open(ClusterPath, 'w')
|
||||
writeToFile.write(config['ClusterConfigMaster'])
|
||||
|
||||
command = 'galera_new_cluster'
|
||||
ProcessUtilities.normalExecutioner(command)
|
||||
|
||||
self.config['masterServerMessage'] = 'Successfully attached to cluster. [200]'
|
||||
self.PostStatus()
|
||||
|
||||
except BaseException as msg:
|
||||
if type == 'Child':
|
||||
self.config['failoverServerMessage'] = 'Failed to attach, error %s [404].' % (str(msg))
|
||||
self.PostStatus()
|
||||
else:
|
||||
self.config['masterServerMessage'] = 'Failed to attach, error %s [404].' % (str(msg))
|
||||
self.PostStatus()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description='CyberPanel Installer')
|
||||
@@ -71,7 +110,9 @@ def main():
|
||||
uc = ClusterManager()
|
||||
|
||||
if args.function == 'DetachCluster':
|
||||
uc.DetechFromCluster()
|
||||
uc.DetechFromCluster(args.type)
|
||||
elif args.function == 'SetupCluster':
|
||||
uc.SetupCluster(args.type)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user