mirror of https://github.com/Aidaho12/haproxy-wi
v8.0.1: Update NGINX service handling and fix template service lookup
Refactor NGINX service command execution for dockerized environments, improving status and process parsing. Fix an issue in the service template by correcting session storage key handling and ensure correct directory ownership initialization.pull/399/head
parent
c421b9c437
commit
77701e1d9f
|
@ -3,6 +3,8 @@ from flask_caching import Cache
|
|||
from flask_jwt_extended import JWTManager
|
||||
from flask_apscheduler import APScheduler
|
||||
|
||||
from app.modules.common.common import set_correct_owner
|
||||
|
||||
app = Flask(__name__)
|
||||
app.config.from_object('app.config.Configuration')
|
||||
app.jinja_env.add_extension('jinja2.ext.do')
|
||||
|
@ -24,6 +26,8 @@ create_tables()
|
|||
default_values()
|
||||
update_all()
|
||||
|
||||
set_correct_owner('/var/lib/roxy-wi')
|
||||
|
||||
from app.api.routes import bp as api_bp
|
||||
|
||||
app.register_blueprint(api_bp, url_prefix='/api')
|
||||
|
|
|
@ -397,7 +397,7 @@
|
|||
{% endif %}
|
||||
showHapservers(ip, hostnamea, '{{service}}');
|
||||
{% for s in servers %}
|
||||
sessionStorage.removeItem('check-service-{{ service }}-{{s.2}}')
|
||||
sessionStorage.removeItem('check-service-{{ service }}-{{s.0}}')
|
||||
check_service_status({{s.0}}, '{{s.2}}', '{{service}}');
|
||||
{% endfor %}
|
||||
</script>
|
||||
|
|
|
@ -106,19 +106,31 @@ class ServiceView(MethodView):
|
|||
elif service == 'nginx':
|
||||
is_dockerized = service_sql.select_service_setting(server_id, service, 'dockerized')
|
||||
if is_dockerized == '1':
|
||||
cmd = ("docker exec -it {container_name} /usr/sbin/nginx -v 2>&1|awk '{print $3}' && systemctl status nginx "
|
||||
"|grep -e 'Active'|awk '{print $2, $9$10$11$12$13}' && ps ax |grep nginx:|grep -v grep |wc -l")
|
||||
container_name = sql.get_setting(f'{service}_container_name')
|
||||
cmd = (f"sudo docker exec -it {container_name} /usr/sbin/nginx -v 2>&1|awk '{{print $3}}' && "
|
||||
f"docker ps -a -f name={container_name} --format '{{{{.Status}}}}' && ps ax |grep nginx:|grep -v grep |wc -l")
|
||||
out = server_mod.ssh_command(server.ip, cmd)
|
||||
out = out.replace('\n', '')
|
||||
out1 = out.split('\r')
|
||||
if out1[0] == 'from':
|
||||
out1[0] = ''
|
||||
out1[1] = out1[1].split(')')[1]
|
||||
else:
|
||||
out1[0] = out1[0].split('/')[1]
|
||||
else:
|
||||
cmd = ("/usr/sbin/nginx -v 2>&1|awk '{print $3}' && systemctl status nginx |grep -e 'Active'"
|
||||
"|awk '{print $2, $9$10$11$12$13}' && ps ax |grep nginx:|grep -v grep |wc -l")
|
||||
try:
|
||||
out = server_mod.ssh_command(server.ip, cmd)
|
||||
out1 = out.split()
|
||||
out = out.replace('\n', '')
|
||||
out1 = out.split('\r')
|
||||
out1[0] = out1[0].split('/')[1]
|
||||
out1[1] = out1[1].split(';')[1]
|
||||
try:
|
||||
data = {
|
||||
"Version": out1[0].split('/')[1],
|
||||
"Uptime": out1[2],
|
||||
"Process": out1[3],
|
||||
"Status": self._service_status(out1[3])}
|
||||
"Version": out1[0],
|
||||
"Uptime": out1[1],
|
||||
"Process": out1[2],
|
||||
"Status": self._service_status(out1[2])}
|
||||
except IndexError:
|
||||
return ErrorResponse(error='NGINX service not found').model_dump(mode='json'), 404
|
||||
except Exception as e:
|
||||
|
@ -137,13 +149,18 @@ class ServiceView(MethodView):
|
|||
for k in out:
|
||||
servers_with_status.append(k)
|
||||
data = {
|
||||
"Version": servers_with_status[0][0].split('/')[1],
|
||||
"Version": servers_with_status[0][0].split('/')[1].split(' ')[0],
|
||||
"Uptime": servers_with_status[0][1].split(':')[1].strip(),
|
||||
"Process": servers_with_status[0][2].split(' ')[1],
|
||||
"Status": self._service_status(servers_with_status[0][2].split(' ')[1])
|
||||
}
|
||||
except IndexError:
|
||||
return ErrorResponse(error='Apache service not found').model_dump(mode='json'), 404
|
||||
data = {
|
||||
"Version": '',
|
||||
"Uptime": '',
|
||||
"Process": 0,
|
||||
"Status": self._service_status('0')
|
||||
}
|
||||
except Exception as e:
|
||||
data = ErrorResponse(error=str(e)).model_dump(mode='json')
|
||||
elif service == 'keepalived':
|
||||
|
@ -175,7 +192,7 @@ class ServiceView(MethodView):
|
|||
return data
|
||||
|
||||
@staticmethod
|
||||
def _service_status(process_num: int) -> str:
|
||||
def _service_status(process_num: str) -> str:
|
||||
if process_num == '0':
|
||||
return 'stopped'
|
||||
return 'running'
|
||||
|
|
Loading…
Reference in New Issue