24 lines
870 B
Rust
24 lines
870 B
Rust
|
|
//! varde-daemon library surface.
|
||
|
|
//!
|
||
|
|
//! The daemon is a binary, but its internals are exposed as a library so
|
||
|
|
//! integration tests can run real daemons in-process on ephemeral sockets.
|
||
|
|
|
||
|
|
pub mod config;
|
||
|
|
pub mod daemon;
|
||
|
|
pub mod server;
|
||
|
|
|
||
|
|
use std::sync::Arc;
|
||
|
|
|
||
|
|
use anyhow::{Context, Result};
|
||
|
|
|
||
|
|
/// Run a daemon with the given config until the future is dropped or the
|
||
|
|
/// listener fails. Binds the socket before returning control to the
|
||
|
|
/// runtime so callers can rely on it existing once this future is polled.
|
||
|
|
pub async fn run(config: config::Config) -> Result<()> {
|
||
|
|
std::fs::create_dir_all(&config.store_dir)
|
||
|
|
.with_context(|| format!("creating store directory {}", config.store_dir.display()))?;
|
||
|
|
let listener = server::bind_socket(&config.socket_path)?;
|
||
|
|
let daemon = Arc::new(daemon::Daemon::new(config));
|
||
|
|
server::serve(listener, daemon).await
|
||
|
|
}
|