v8.0.1: Handle missing services and improve error handling

Enhanced error handling for missing NGINX and Keepalived services. Updated JavaScript to handle 404 errors and provide clearer messages in UI if services are not installed.
pull/399/head
Aidaho 3 months ago
parent 1f9942aa7d
commit 8ef721d72c

@ -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);

@ -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');

@ -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);
}
});

@ -123,8 +123,11 @@ class ServiceView(MethodView):
out = server_mod.ssh_command(server.ip, cmd)
out = out.replace('\n', '')
out1 = out.split('\r')
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

Loading…
Cancel
Save