diff --git a/lib/g3-daemon/Cargo.toml b/lib/g3-daemon/Cargo.toml index 3b95c2929..4a3e80dae 100644 --- a/lib/g3-daemon/Cargo.toml +++ b/lib/g3-daemon/Cargo.toml @@ -14,7 +14,6 @@ cfg-if.workspace = true slog = { workspace = true, features = ["max_level_trace", "release_max_level_info"] } slog-scope = "4" slog-stdlog = "4.1" -daemonize = "0.5" futures-util.workspace = true async-trait.workspace = true yaml-rust.workspace = true @@ -48,6 +47,9 @@ g3-http = { workspace = true, optional = true } [target.'cfg(target_os = "linux")'.dependencies] g3-journal.workspace = true +[target.'cfg(unix)'.dependencies] +daemonize = "0.5" + [features] default = [] register = ["g3-yaml/http", "dep:http", "dep:serde_json", "dep:g3-http"] diff --git a/lib/g3-daemon/src/daemonize.rs b/lib/g3-daemon/src/daemonize.rs index 6cee3d941..1b26740c0 100644 --- a/lib/g3-daemon/src/daemonize.rs +++ b/lib/g3-daemon/src/daemonize.rs @@ -17,7 +17,6 @@ use std::fs::OpenOptions; use anyhow::anyhow; -use daemonize::Daemonize; use log::debug; use crate::opts::DaemonArgs; @@ -30,7 +29,10 @@ pub fn check_enter(args: &DaemonArgs) -> anyhow::Result<()> { Ok(()) } +#[cfg(unix)] fn enter(args: &DaemonArgs) -> anyhow::Result<()> { + use daemonize::Daemonize; + let stdout = OpenOptions::new().write(true).open("/dev/null")?; let stderr = OpenOptions::new().write(true).open("/dev/null")?; let mut daemonize = Daemonize::new() @@ -44,3 +46,8 @@ fn enter(args: &DaemonArgs) -> anyhow::Result<()> { daemonize.start().map_err(|e| anyhow!("daemonize: {e}")) } + +#[cfg(windows)] +fn enter(_args: &DaemonArgs) -> anyhow::Result<()> { + Err(anyhow!("daemon mode is not implemented on Windows")) +}