diff --git a/agent/src/agent.rs b/agent/src/agent.rs index ec73349..baba1e4 100644 --- a/agent/src/agent.rs +++ b/agent/src/agent.rs @@ -296,9 +296,15 @@ impl Agent { // Clone or update repository let git_result = self.ensure_git_repository(git_url, git_branch, working_dir, api_key_file).await; - // Execute nixos-rebuild if git operation succeeded - run detached to avoid killing current agent + // Execute nixos-rebuild if git operation succeeded - run detached but log output let rebuild_result = if git_result.is_ok() { info!("Git repository ready, executing nixos-rebuild in detached mode"); + let log_file = std::fs::OpenOptions::new() + .create(true) + .append(true) + .open("/var/log/cm-dashboard/nixos-rebuild.log") + .map_err(|e| anyhow::anyhow!("Failed to open rebuild log: {}", e))?; + tokio::process::Command::new("nohup") .arg("sudo") .arg("/run/current-system/sw/bin/nixos-rebuild") @@ -310,8 +316,8 @@ impl Agent { .arg(".") .current_dir(working_dir) .stdin(std::process::Stdio::null()) - .stdout(std::process::Stdio::null()) - .stderr(std::process::Stdio::null()) + .stdout(std::process::Stdio::from(log_file.try_clone().unwrap())) + .stderr(std::process::Stdio::from(log_file)) .spawn() } else { return git_result.and_then(|_| unreachable!());