diff --git a/Cargo.toml b/Cargo.toml index e5c1eb4..5189ad9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" anyhow = "1.0.86" clap = { version = "4.5.16", features = ["derive"] } ctrlc = { version = "3.4.5", features = ["termination"] } +daemonize = "0.5.0" env_logger = "0.11.5" fs-tail = "0.1.4" log = "0.4.22" diff --git a/src/cli.rs b/src/cli.rs index d165269..16a6077 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -8,10 +8,14 @@ pub struct List { #[derive(Debug, clap::Parser)] pub struct Serve { /// Path to the unix socket to serve + #[arg(long = "socket")] pub unix_socket: Option, /// Storage directory #[arg(short = 'd', long = "dir")] pub dir: Option, + /// Daemonize on startup + #[arg(long = "daemonize")] + pub daemonize: bool, } #[derive(Debug, clap::Parser)] diff --git a/src/serve.rs b/src/serve.rs index a95e28c..5a30269 100644 --- a/src/serve.rs +++ b/src/serve.rs @@ -18,6 +18,7 @@ use std::{ use crate::{cli, msg, utils}; use anyhow::{Context, Result}; +use daemonize::Daemonize; /// A trace ID, used to coordinate logs/traces from multiple processes. #[derive(Clone, Debug, Eq, PartialEq, Hash)] @@ -244,6 +245,10 @@ fn cleaner_thread(st: Arc) { } pub fn run(cli: cli::Serve) -> Result<()> { + if cli.daemonize { + Daemonize::new().start().context("daemonizing")?; + } + let dir: PathBuf = match cli.dir { None => { let xdg = xdg::BaseDirectories::with_prefix(utils::XDG_PREFIX)?;