forked from NationTech/harmony
fix(load-balancer): implement missing HAProxy reload and sanitize output handling
Implement the `reload_restart` method in `LoadBalancerConfig` to ensure proper HAProxy configuration management. Additionally, enhance SSH command execution by sanitizing and logging outputs effectively. This ensures robust handling of HAProxy configurations and improves debugging capabilities through trace-level logs.
This commit is contained in:
@@ -5,7 +5,7 @@ use opnsense_config_xml::{
|
||||
Frontend, HAProxy, HAProxyBackend, HAProxyHealthCheck, HAProxyServer, OPNsense,
|
||||
};
|
||||
|
||||
use crate::config::OPNsenseShell;
|
||||
use crate::{config::OPNsenseShell, Error};
|
||||
|
||||
pub struct LoadBalancerConfig<'a> {
|
||||
opnsense: &'a mut OPNsense,
|
||||
@@ -56,4 +56,13 @@ impl<'a> LoadBalancerConfig<'a> {
|
||||
pub fn add_servers(&mut self, mut servers: Vec<HAProxyServer>) {
|
||||
self.with_haproxy(|haproxy| haproxy.servers.servers.append(&mut servers));
|
||||
}
|
||||
|
||||
pub async fn reload_restart(&self) -> Result<(), Error> {
|
||||
self.opnsense_shell.exec("configctl haproxy stop").await?;
|
||||
self.opnsense_shell.exec("configctl template reload OPNsense/HAProxy").await?;
|
||||
self.opnsense_shell.exec("configctl template reload OPNsense/Syslog").await?;
|
||||
self.opnsense_shell.exec("configctl haproxy configtest").await?;
|
||||
self.opnsense_shell.exec("configctl haproxy start").await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user