agent: use socket activation, port credential + provide nixos module
This commit is contained in:
parent
30e76e3291
commit
efae851a9a
4 changed files with 134 additions and 14 deletions
|
|
@ -5,7 +5,6 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
sidebus-common = { workspace = true }
|
||||
clap = { version = "4.5.40", features = ["derive"] }
|
||||
eyre = "0.6.12"
|
||||
tokio = { version = "1.46.0", features = ["full"] }
|
||||
tokio-stream = "0.1.17"
|
||||
|
|
@ -13,3 +12,4 @@ tokio-vsock = "0.7.1"
|
|||
tracing = "0.1.41"
|
||||
tracing-subscriber = "0.3.19"
|
||||
zbus = { workspace = true }
|
||||
listenfd = "1.0.2"
|
||||
|
|
|
|||
|
|
@ -1,27 +1,28 @@
|
|||
use clap::Parser;
|
||||
use eyre::OptionExt;
|
||||
use tokio::net::UnixListener;
|
||||
use tracing::info;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct AgentCli {
|
||||
listen_path: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> eyre::Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
let cli = AgentCli::parse();
|
||||
let creds_dir = std::path::PathBuf::try_from(std::env::var("CREDENTIALS_DIRECTORY")?)?;
|
||||
let vsock_port = std::fs::read_to_string(creds_dir.join("sidebus.port"))?
|
||||
.trim()
|
||||
.parse::<u32>()?;
|
||||
|
||||
let unix_listener = UnixListener::from_std(
|
||||
listenfd::ListenFd::from_env()
|
||||
.take_unix_listener(0)?
|
||||
.ok_or_eyre("no unix listener provided")?,
|
||||
)?;
|
||||
info!("listening for unix clients");
|
||||
|
||||
let unix_addr = cli.listen_path;
|
||||
let unix_listener = UnixListener::bind(unix_addr.clone())?;
|
||||
info!(%unix_addr, "listening for unix clients");
|
||||
while let Ok((unix_client, client_addr)) = unix_listener.accept().await {
|
||||
info!(?client_addr, "new unix client");
|
||||
tokio::spawn(async move {
|
||||
let vsock_addr = zbus::Address::from(zbus::address::Transport::Vsock(
|
||||
zbus::address::transport::Vsock::new(2, 4269),
|
||||
zbus::address::transport::Vsock::new(2, vsock_port),
|
||||
));
|
||||
let vsock_conn = zbus::connection::Builder::address(vsock_addr)
|
||||
.unwrap()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue