diff --git a/app/static/js/ha.js b/app/static/js/ha.js index e45bdb38..66192454 100644 --- a/app/static/js/ha.js +++ b/app/static/js/ha.js @@ -708,10 +708,13 @@ function get_keepalived_ver(div_id, server_ip) { $.ajax({ url: api_prefix + "/service/keepalived/" + server_ip + "/status", contentType: "application/json; charset=utf-8", - success: function (data) { - if (data.status === 'failed') { + statusCode: { + 404: function (xhr) { div_id.text('Keepalived has not installed'); - } else if (!data.Version) { + } + }, + success: function (data) { + if (!data.Version) { div_id.text('Keepalived has not installed'); } else { div_id.text(data.Version); diff --git a/app/static/js/install.js b/app/static/js/install.js index 1a51677e..c67f40f8 100644 --- a/app/static/js/install.js +++ b/app/static/js/install.js @@ -254,7 +254,7 @@ function showServiceVersion(service) { } }, success: function (data) { - if (data.status === 'failed') { + if (data.status === 'failed' || !data.Version) { ver_div.text(service + ' has not installed'); install_div.text('Install'); install_div.attr('title', 'Install'); diff --git a/app/static/js/script.js b/app/static/js/script.js index 7e488c3f..f46a204f 100644 --- a/app/static/js/script.js +++ b/app/static/js/script.js @@ -132,7 +132,7 @@ $.ajaxSetup({ headers: {"X-CSRF-TOKEN": csrf_token}, }); $(document).ajaxError(function myErrorHandler(event, xhr, ajaxOptions, thrownError) { - if (xhr.status != 401) { + if (xhr.status != 401 && xhr.status != 404) { toastr.error(xhr.responseJSON.error); } }); diff --git a/app/views/service/views.py b/app/views/service/views.py index 3d86746c..5ff4eeb5 100644 --- a/app/views/service/views.py +++ b/app/views/service/views.py @@ -123,8 +123,11 @@ class ServiceView(MethodView): out = server_mod.ssh_command(server.ip, cmd) out = out.replace('\n', '') out1 = out.split('\r') - out1[0] = out1[0].split('/')[1] - out1[1] = out1[1].split(';')[1] + try: + out1[0] = out1[0].split('/')[1] + out1[1] = out1[1].split(';')[1] + except IndexError: + return ErrorResponse(error='NGINX service not found').model_dump(mode='json'), 404 try: data = { "Version": out1[0], @@ -164,11 +167,21 @@ class ServiceView(MethodView): except Exception as e: data = ErrorResponse(error=str(e)).model_dump(mode='json') elif service == 'keepalived': + try: + os_info = server_sql.select_os_info(server_id) + except RoxywiResourceNotFound: + raise RoxywiResourceNotFound('Cannot find system information') + if "CentOS" in os_info or "Redhat" in os_info: + kp_proc_name = 'keepalived -D' + else: + kp_proc_name = 'keepalived --dont-fork' cmd = ("sudo /usr/sbin/keepalived -v 2>&1|head -1|awk '{print $2}' && sudo systemctl status keepalived |grep -e 'Active'" - "|awk '{print $2, $9$10$11$12$13}' && ps ax |grep 'keepalived -D'|grep -v grep |wc -l") + f"|awk '{{print $2, $9$10$11$12$13}}' && ps ax |grep '{kp_proc_name}'|grep -v grep |wc -l") try: out = server_mod.ssh_command(server.ip, cmd) out1 = out.split() + if out1[0].split('\r')[0] == '/usr/sbin/keepalived:': + return ErrorResponse(error='Keepalived service not found').model_dump(mode='json'), 404 data = {"Version": out1[0].split('\r')[0], "Uptime": out1[2], "Process": out1[3], 'Status': self._service_status(out1[3])} except IndexError: return ErrorResponse(error='Keepalived service not found').model_dump(mode='json'), 404