Skip to content

Commit 4923f06

Browse files
committed
feature: add option to switch to master again
1 parent 64ca253 commit 4923f06

File tree

4 files changed

+59
-2
lines changed

4 files changed

+59
-2
lines changed

CLManager/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
url(r'^listPackages$', views.listPackages, name='listPackagesCL'),
77
url(r'^monitorUsage$', views.monitorUsage, name='monitorUsage'),
88
url(r'^CageFS$', views.CageFS, name='CageFS'),
9-
109
url(r'^submitCageFSInstall$', views.submitCageFSInstall, name='submitCageFSInstall'),
10+
1111
# url(r'^submitWebsiteListing$', views.getFurtherAccounts, name='submitWebsiteListing'),
1212
# url(r'^enableOrDisable$', views.enableOrDisable, name='enableOrDisable'),
1313
# url(r'^submitCreatePackage$', views.submitCreatePackage, name='submitCreatePackageCL'),

cloudAPI/cloudManager.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2970,3 +2970,35 @@ def UptimeMonitor(self):
29702970
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
29712971
final_json = json.dumps(final_dic)
29722972
return HttpResponse(final_json)
2973+
2974+
def CheckMasterNode(self):
2975+
try:
2976+
2977+
command = 'systemctl status mysql'
2978+
result = ProcessUtilities.outputExecutioner(command)
2979+
2980+
if result.find('active (running)') > -1:
2981+
final_json = json.dumps({'status': 1})
2982+
else:
2983+
final_json = json.dumps({'status': 0, 'error_message': 'MySQL on Main node is not running.'})
2984+
2985+
return HttpResponse(final_json)
2986+
2987+
except BaseException as msg:
2988+
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
2989+
final_json = json.dumps(final_dic)
2990+
return HttpResponse(final_json)
2991+
2992+
def SyncToMaster(self):
2993+
try:
2994+
2995+
command = '/usr/local/CyberCP/bin/python /usr/local/CyberCP/plogical/ClusterManager.py --function SyncToMaster --type Master'
2996+
ProcessUtilities.executioner(command)
2997+
2998+
final_json = json.dumps({'status': 1})
2999+
return HttpResponse(final_json)
3000+
3001+
except BaseException as msg:
3002+
final_dic = {'status': 0, 'fetchStatus': 0, 'error_message': str(msg)}
3003+
final_json = json.dumps(final_dic)
3004+
return HttpResponse(final_json)

cloudAPI/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,12 @@ def router(request):
5050
return cm.DetachCluster()
5151
elif controller == 'DebugCluster':
5252
return cm.DebugCluster()
53+
elif controller == 'CheckMasterNode':
54+
return cm.CheckMasterNode()
5355
elif controller == 'UptimeMonitor':
5456
return cm.UptimeMonitor()
57+
elif controller == 'SyncToMaster':
58+
return cm.SyncToMaster()
5559
elif controller == 'FetchMasterBootStrapStatus':
5660
return cm.FetchMasterBootStrapStatus()
5761
elif controller == 'FetchChildBootStrapStatus':

plogical/ClusterManager.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ def SyncNow(self):
357357
self.PostStatus('Data and SSL certificates currently synced.')
358358

359359
except BaseException as msg:
360-
self.PostStatus('Failed to create pending vhosts, error %s [404].' % (str(msg)))
360+
self.PostStatus('Failed to sync data, error %s [404].' % (str(msg)))
361361

362362
def PingNow(self):
363363
try:
@@ -423,6 +423,25 @@ def Uptime(self):
423423
except BaseException as msg:
424424
logging.writeToFile('%s. [31:404]' % (str(msg)))
425425

426+
def SyncToMaster(self):
427+
try:
428+
429+
self.PostStatus('Syncing data from home directory to Main server..')
430+
431+
command = "rsync -avzp -e 'ssh -o StrictHostKeyChecking=no -p %s -i /root/.ssh/cyberpanel' /home root@%s:/" % (self.config['masterServerSSHPort'], self.config['masterServerIP'])
432+
ProcessUtilities.normalExecutioner(command)
433+
434+
self.PostStatus('Syncing SSL certificates to Main server..')
435+
436+
command = "rsync -avzp -e 'ssh -o StrictHostKeyChecking=no -p %s -i /root/.ssh/cyberpanel' /etc/letsencrypt root@%s:/etc" % (
437+
self.config['masterServerSSHPort'], self.config['masterServerIP'])
438+
ProcessUtilities.normalExecutioner(command)
439+
440+
self.PostStatus('Data back to main.')
441+
442+
except BaseException as msg:
443+
self.PostStatus('Failed to sync data, error %s [404].' % (str(msg)))
444+
426445

427446
def main():
428447
parser = argparse.ArgumentParser(description='CyberPanel Installer')
@@ -453,6 +472,8 @@ def main():
453472
uc.UptimeMonitor()
454473
elif args.function == 'Uptime':
455474
uc.Uptime()
475+
elif args.function == 'SyncToMaster':
476+
uc.SyncToMaster()
456477

457478

458479
if __name__ == "__main__":

0 commit comments

Comments
 (0)