Files
continuum-proxy/src/go2rtc.rs
T

34 lines
1.1 KiB
Rust

use std::process::Stdio;
use std::time::Duration;
use tokio::process::Command;
use tracing::{error, info, warn};
/// Supervises the go2rtc subprocess used for camera restreaming (RTSP/USB -> WebRTC).
/// Restarts it with a fixed backoff whenever it exits, for as long as the daemon runs.
pub async fn watchdog(bin: String, config_path: String) {
loop {
info!(%bin, %config_path, "starting go2rtc");
let spawned = Command::new(&bin)
.arg("-config")
.arg(&config_path)
.stdout(Stdio::null())
.stderr(Stdio::inherit())
.kill_on_drop(true)
.spawn();
match spawned {
Ok(mut child) => match child.wait().await {
Ok(status) => warn!(%status, "go2rtc exited, restarting after backoff"),
Err(err) => error!(?err, "failed to wait on go2rtc process"),
},
Err(err) => {
error!(?err, "failed to spawn go2rtc, is it installed and on PATH?");
}
}
tokio::time::sleep(Duration::from_secs(5)).await;
}
}