From 211d40815f59ab5ab6b3e2a619b93203f43108cf Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sun, 25 Jan 2026 09:12:28 +0000 Subject: [PATCH] feat: remowt-systemd --- --- /dev/null +++ b/crates/remowt-systemd/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "remowt-systemd" +description = "systemd control endpoint for remowt/bifrostlink (over D-Bus)" +version.workspace = true +edition = "2021" + +[dependencies] +bifrostlink.workspace = true +bifrostlink-macros.workspace = true +serde = { workspace = true, features = ["derive"] } +thiserror = "1" +zbus = { workspace = true, features = ["tokio"] } --- /dev/null +++ b/crates/remowt-systemd/src/lib.rs @@ -0,0 +1,54 @@ +use bifrostlink::declarative::endpoints; +use bifrostlink::Config; +use serde::{Deserialize, Serialize}; +use zbus::proxy; +use zbus::zvariant::OwnedObjectPath; + +pub struct Systemd; + +#[derive(Serialize, Deserialize, Debug, thiserror::Error)] +pub enum Error { + #[error("systemd request failed: {0}")] + Failed(String), +} + +#[proxy( + interface = "org.freedesktop.systemd1.Manager", + default_service = "org.freedesktop.systemd1", + default_path = "/org/freedesktop/systemd1" +)] +trait Manager { + fn start_unit(&self, name: &str, mode: &str) -> zbus::Result; + fn stop_unit(&self, name: &str, mode: &str) -> zbus::Result; +} + +async fn manager() -> Result, Error> { + let conn = zbus::Connection::system() + .await + .map_err(|e| Error::Failed(e.to_string()))?; + ManagerProxy::new(&conn) + .await + .map_err(|e| Error::Failed(e.to_string())) +} + +#[endpoints(ns = 5)] +impl Systemd { + #[endpoints(id = 1)] + async fn start(&self, unit: String) -> Result<(), Error> { + manager() + .await? + .start_unit(&unit, "replace") + .await + .map_err(|e| Error::Failed(e.to_string()))?; + Ok(()) + } + #[endpoints(id = 2)] + async fn stop(&self, unit: String) -> Result<(), Error> { + manager() + .await? + .stop_unit(&unit, "replace") + .await + .map_err(|e| Error::Failed(e.to_string()))?; + Ok(()) + } +} -- gitstuff