config + stop outsourcing other commands
This commit is contained in:
@@ -52,6 +52,14 @@ pub struct EnrollArgs {
|
||||
/// Path to the agent config file to write.
|
||||
#[arg(long, default_value = config::DEFAULT_CONFIG_PATH)]
|
||||
pub config: PathBuf,
|
||||
|
||||
/// Reload a running daemon after writing config.
|
||||
#[arg(long)]
|
||||
pub reload_running: bool,
|
||||
|
||||
/// Path to pid file used when `--reload-running` is enabled.
|
||||
#[arg(long, default_value = DEFAULT_PID_FILE)]
|
||||
pub pid_file: PathBuf,
|
||||
}
|
||||
|
||||
#[derive(Args)]
|
||||
|
||||
@@ -22,6 +22,12 @@ async fn main() -> Result<()> {
|
||||
let config = enroll::enroll(&args.server_url, &args.enroll_token, &args.config).await?;
|
||||
println!("agent_id={}", config.agent_id);
|
||||
println!("config={}", args.config.display());
|
||||
if args.reload_running {
|
||||
match serve::reload_daemon(&args.pid_file) {
|
||||
Ok(()) => println!("reload=signaled pid_file={}", args.pid_file.display()),
|
||||
Err(err) => ::tracing::warn!(error = %err, pid_file = %args.pid_file.display(), "enroll completed but daemon reload failed"),
|
||||
}
|
||||
}
|
||||
}
|
||||
Command::InitConfig(args) => init_config(args)?,
|
||||
Command::Reload(args) => serve::reload_daemon(&args.pid_file)?,
|
||||
|
||||
@@ -105,13 +105,19 @@ fn read_pid(path: &Path) -> Result<i32> {
|
||||
}
|
||||
|
||||
fn send_hup(pid: i32) -> Result<()> {
|
||||
let status = std::process::Command::new("kill")
|
||||
.arg("-HUP")
|
||||
.arg(pid.to_string())
|
||||
.status()
|
||||
.context("failed to invoke kill -HUP")?;
|
||||
if !status.success() {
|
||||
anyhow::bail!("kill -HUP failed for pid {pid}");
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use nix::sys::signal::{Signal, kill};
|
||||
use nix::unistd::Pid;
|
||||
|
||||
kill(Pid::from_raw(pid), Signal::SIGHUP)
|
||||
.with_context(|| format!("failed to send SIGHUP to pid {pid}"))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
{
|
||||
let _ = pid;
|
||||
anyhow::bail!("reload is only supported on Unix (SIGHUP unavailable on this platform)")
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user