macro_rules! async_daemonize {
($realmain:ident) => { ... };
}
Expand description
This macro is used for a standard way of daemonizing darkfi binaries with TOML config file configuration, and argument parsing.
It also spawns a multithreaded async executor and passes it into the given function.
The Cargo.toml dependencies needed for this are:
darkfi = { path = "../../", features = ["util"] }
easy-parallel = "3.2.0"
signal-hook-async-std = "0.2.2"
signal-hook = "0.3.15"
simplelog = "0.12.0"
smol = "1.2.5"
# Argument parsing
serde = {version = "1.0.135", features = ["derive"]}
structopt = "0.3.26"
structopt-toml = "0.5.1"
Example usage:
use darkfi::{async_daemonize, cli_desc, Result};
use smol::stream::StreamExt;
use structopt_toml::{serde::Deserialize, structopt::StructOpt, StructOptToml};
const CONFIG_FILE: &str = "daemond_config.toml";
const CONFIG_FILE_CONTENTS: &str = include_str!("../daemond_config.toml");
#[derive(Clone, Debug, Deserialize, StructOpt, StructOptToml)]
#[serde(default)]
#[structopt(name = "daemond", about = cli_desc!())]
struct Args {
#[structopt(short, long)]
/// Configuration file to use
config: Option<String>,
#[structopt(short, long)]
/// Set log file to ouput into
log: Option<String>,
#[structopt(short, parse(from_occurrences))]
/// Increase verbosity (-vvv supported)
verbose: u8,
}
async_daemonize!(realmain);
async fn realmain(args: Args, ex: Arc<smol::Executor<'static>>) -> Result<()> {
println!("Hello, world!");
Ok(())
}