Improve error handling in tools list and adjust status check command

Enhanced error handling in tools list loop within the 'common.py' file to provide more specific error messages. Additionally, the command for checking a tool's status was adjusted to remove unnecessary sudo usage. Also, updated the service check in the 'roxy.py' file from 'sshd' to 'rsyslog'.
pull/375/head
Aidaho 2024-03-14 11:20:16 +03:00
parent 8322ad4089
commit b185ee78c8
2 changed files with 10 additions and 4 deletions

View File

@ -20,7 +20,7 @@ def is_docker() -> bool:
for line in f:
if re.match("\d+:[\w=]+:/docker(-[ce]e)?/\w+", line):
return True
return_out = server_mod.subprocess_execute_with_rc('systemctl status sshd')
return_out = server_mod.subprocess_execute_with_rc('systemctl status rsyslog')
if return_out['rc']:
return True
return False

View File

@ -17,8 +17,14 @@ def get_services_status(update_cur_ver=0):
try:
for s, v in services_name.items():
status = is_tool_active(s)
services.append([s, status, v])
try:
status = is_tool_active(s)
except Exception as e:
raise Exception(f'error: Cannot get status for tool {s}: {e}')
try:
services.append([s, status, v])
except Exception as e:
raise Exception(f'error: Cannot combine status for tool {s}: {e}')
except Exception as e:
raise Exception(f'error: Cannot get tools status: {e}')
@ -55,7 +61,7 @@ def update_roxy_wi(service: str) -> str:
def is_tool_active(tool_name: str) -> str:
is_in_docker = roxywi_mod.is_docker()
if is_in_docker:
cmd = f"sudo supervisorctl status {tool_name}|awk '{{print $2}}'"
cmd = f"supervisorctl status {tool_name}|awk '{{print $2}}'"
else:
cmd = f"systemctl is-active {tool_name}"
status, stderr = server_mod.subprocess_execute(cmd)