pub fn maybe_daemonize(
detach: bool,
working_dir: Option<String>,
pid_file: Option<String>,
) -> Result<()>Expand description
Daemonize the process if requested
This function should be called early in main(), before creating the tokio runtime.
It uses the daemonize crate to properly fork and detach from the terminal.
§Arguments
detach- Whether to detach from the terminalworking_dir- Optional working directory to change to after daemonizingpid_file- Optional PID file path (defaults to runtime-appropriate location)
§Returns
Returns Ok(()) if daemonization succeeded or was not requested.
Returns Err if daemonization failed.
§Example
ⓘ
// Call before creating tokio runtime
maybe_daemonize(cmd.detach, cmd.server.working_dir.clone(), cmd.server.pid_file.clone())?;
// Now create runtime and start server
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(async { /* server code */ });