Restart lqos_api after Caddy changes

(cherry picked from commit ffc0fd619a)
This commit is contained in:
Herbert Wolverson committed 2026-06-14 15:14:14 -05:00
1 parent c2075de738
commit 7fe9677477
1 file changed
+33 -5
+33 -5
View File
@@ -102,7 +102,7 @@ pub fn ssl_status(config: &Config, preferred_host: Option<&str>) -> SslStatus {
/// - updates `/etc/lqos.conf`
/// - runs the Caddy installer helper if needed
/// - writes `/etc/caddy/Caddyfile`
/// - schedules a delayed service switch that restarts `caddy.service` and `lqosd.service`
/// - schedules a delayed service switch that restarts `caddy.service`, `lqosd.service`, and `lqos_api.service`
pub fn enable_runtime_ssl(
external_hostname: Option<String>,
preferred_host: Option<&str>,
@@ -149,7 +149,7 @@ pub fn enable_runtime_ssl(
/// - updates `/etc/lqos.conf`
/// - removes the managed `/etc/caddy/Caddyfile`
/// - runs the Caddy disable helper when LibreQoS owns that setup
/// - schedules a delayed service switch that restarts `lqosd.service`
/// - schedules a delayed service switch that restarts `lqosd.service` and `lqos_api.service`
pub fn disable_runtime_ssl(preferred_host: Option<&str>) -> Result<SslActionOutcome> {
let existing = (*lqos_config::load_config()?).clone();
let ssl = existing
@@ -556,7 +556,7 @@ fn render_managed_caddyfile(plan: &SslRuntimePlan) -> String {
}
fn enable_runtime_command() -> &'static str {
"systemctl enable caddy.service && systemctl restart caddy.service && systemctl restart lqosd.service"
"systemctl enable caddy.service && systemctl restart caddy.service && systemctl restart lqosd.service && systemctl restart lqos_api.service"
}
fn enable_setup_command() -> &'static str {
@@ -564,7 +564,7 @@ fn enable_setup_command() -> &'static str {
}
fn disable_runtime_command() -> &'static str {
"systemctl stop caddy.service || true; systemctl disable caddy.service || true; systemctl restart lqosd.service"
"systemctl stop caddy.service || true; systemctl disable caddy.service || true; systemctl restart lqosd.service && systemctl restart lqos_api.service"
}
fn schedule_delayed_runtime_switch(command: &str) -> Result<()> {
@@ -582,7 +582,9 @@ fn schedule_delayed_runtime_switch(command: &str) -> Result<()> {
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.with_context(|| format!("Unable to invoke {SYSTEMD_RUN_BIN} for SSL service switch"))?;
.with_context(|| {
format!("Unable to invoke {SYSTEMD_RUN_BIN} for SSL service switch")
})?;
if !status.success() {
bail!("Unable to schedule SSL service switch via systemd-run: {status}");
}
@@ -738,4 +740,30 @@ mod tests {
.enabled
);
}
#[test]
fn runtime_enable_restarts_api_after_caddy_mode_change() {
let command = super::enable_runtime_command();
assert!(command.contains("systemctl restart caddy.service"));
assert!(command.contains("systemctl restart lqosd.service"));
assert!(command.contains("systemctl restart lqos_api.service"));
assert!(
command.find("systemctl restart lqosd.service")
< command.find("systemctl restart lqos_api.service")
);
}
#[test]
fn runtime_disable_restarts_api_after_caddy_mode_change() {
let command = super::disable_runtime_command();
assert!(command.contains("systemctl disable caddy.service"));
assert!(command.contains("systemctl restart lqosd.service"));
assert!(command.contains("systemctl restart lqos_api.service"));
assert!(
command.find("systemctl restart lqosd.service")
< command.find("systemctl restart lqos_api.service")
);
}
}