Skip to main content

reflect/
reflect.rs

1//! Example service that reflects data.
2
3use clap::Parser;
4use daemonbase::error::ExitError;
5use daemonbase::logging::Logger;
6use daemonbase::process::Process;
7use daemonbase::{logging, process};
8use log::warn;
9
10#[derive(Parser)]
11struct Args {
12    #[command(flatten)]
13    log: logging::Args,
14
15    /// Detach from the terminal
16    #[arg(short, long)]
17    detach: bool,
18
19    #[command(flatten)]
20    process: process::Args,
21}
22
23fn _main() -> Result<(), ExitError> {
24    Logger::init_logging()?;
25    warn!("Logging initialized.");
26
27    let args = Args::parse();
28    let log = Logger::from_config(&args.log.to_config())?;
29    let mut process = Process::from_config(args.process.into_config());
30
31    log.switch_logging(args.detach)?;
32    process.setup_daemon(args.detach)?;
33
34    // This is where you create listener sockets so they can use privileged
35    // ports.
36
37    process.drop_privileges()?;
38
39    warn!("Up and running.");
40
41    // This is where we do something useful later.
42    loop {
43        std::thread::sleep(std::time::Duration::from_secs(60));
44    }
45
46    //Ok(())
47}
48
49fn main() {
50    let _ = _main();
51}