Skip to content

Commit

Permalink
daemonize on demand
Browse files Browse the repository at this point in the history
  • Loading branch information
c-cube committed Aug 23, 2024
1 parent 63dae70 commit b177c05
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Storage directory
#[arg(short = 'd', long = "dir")]
pub dir: Option<String>,
/// Daemonize on startup
#[arg(long = "daemonize")]
pub daemonize: bool,
}

#[derive(Debug, clap::Parser)]
Expand Down
5 changes: 5 additions & 0 deletions src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -244,6 +245,10 @@ fn cleaner_thread(st: Arc<State>) {
}

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)?;
Expand Down

0 comments on commit b177c05

Please sign in to comment.