diff options
-rw-r--r-- | Cargo.lock | 23 | ||||
-rw-r--r-- | hbakd/Cargo.toml | 2 | ||||
-rw-r--r-- | hbakd/src/main.rs | 26 |
3 files changed, 42 insertions, 9 deletions
@@ -29,9 +29,9 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.5" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d664a92ecae85fd0a7392615844904654d1d5f5514837f471ddef4a057aba1b6" +checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5" dependencies = [ "anstyle", "anstyle-parse", @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.4.12" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcfab8ba68f3668e89f6ff60f5b205cea56aa7b769451a59f34b8682f51c056d" +checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c" dependencies = [ "clap_builder", "clap_derive", @@ -215,9 +215,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.4.12" +version = "4.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb7fb5e4e979aec3be7791562fcba452f94ad85e954da024396433e0e25a79e9" +checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7" dependencies = [ "anstream", "anstyle", @@ -293,6 +293,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] +name = "fork" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf2ca97a59201425e7ee4d197c9c4fea282fe87a97d666a580bda889b95b8e88" +dependencies = [ + "libc", +] + +[[package]] name = "generic-array" version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -353,6 +362,8 @@ dependencies = [ name = "hbakd" version = "0.1.0-dev" dependencies = [ + "clap", + "fork", "hbak_common", ] diff --git a/hbakd/Cargo.toml b/hbakd/Cargo.toml index a166b84..1038ceb 100644 --- a/hbakd/Cargo.toml +++ b/hbakd/Cargo.toml @@ -6,4 +6,6 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.4.18", features = ["derive"] } +fork = "0.1.22" hbak_common = { version = "0.1.0-dev", path = "../hbak_common" } diff --git a/hbakd/src/main.rs b/hbakd/src/main.rs index d65f8b4..68d7505 100644 --- a/hbakd/src/main.rs +++ b/hbakd/src/main.rs @@ -4,10 +4,30 @@ use hbak_common::{LocalNodeError, NetworkError}; use std::net::{IpAddr, Ipv6Addr, SocketAddr, TcpListener, TcpStream}; +use clap::Parser; +use fork::{daemon, Fork}; + +#[derive(Debug, Parser)] +#[command(author, version, about, long_about = None)] +/// Background process to serve push and pull requests. +struct Args { + /// Stay attached to the terminal instead of daemonizing. + debug: bool, +} + fn main() { - match serve() { - Ok(_) => {} - Err(e) => eprintln!("Error: {}", e), + let args = Args::parse(); + + if args.debug { + match serve() { + Ok(_) => {} + Err(e) => eprintln!("Error: {}", e), + } + } else if let Ok(Fork::Child) = daemon(false, false) { + match serve() { + Ok(_) => {} + Err(e) => eprintln!("Error: {}", e), + } } } |