aboutsummaryrefslogtreecommitdiff
path: root/hbakd
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2024-01-28 17:54:15 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2024-01-28 17:54:15 +0100
commit50237e9df64527d69c753c1b5d0e4bd810833cfa (patch)
tree2d42c36d06da8ef27bb49ced9b44d678303a06c2 /hbakd
parente00ca09b2705cb9240aed388e4a46f7e31be06ec (diff)
hbakd: daemonize (opt-out for debugging)
Diffstat (limited to 'hbakd')
-rw-r--r--hbakd/Cargo.toml2
-rw-r--r--hbakd/src/main.rs26
2 files changed, 25 insertions, 3 deletions
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),
+ }
}
}