Skip to main content

Crate systemdzbus

Crate systemdzbus 

Source
Expand description

§Systemdzbus

Interact with systemd through DBus with a convenient rust interface. All of the manager proxy types were automatically generated by the CLI tool ‘zbus-xmlgen’. From here I just copied the documentation from the systemd man page to get good descriptions for each function.

The plan is to gradually start wrapping each of the types into more descriptive types informed by the man pages, mainly found in “man org.freedesktop.systemd1”.

§Usage

     use std::error::Error;
     use systemdzbus::SystemCtlBuilder;

     async fn example_get_units() -> Result<(), Box::<dyn Error>> {
       let systemctl = SystemCtlBuilder::new()
         // You may also want to have access to the system bus instead of only the user bus
         .with_system_connection_level()
         .init()
         .await?;

       let units = systemctl.list_units().await?;

       assert!(!units.is_empty());

       Ok(())
     }

You may also access the manager proxy directly if managing the connection yourself suits your needs better. To find out more about how to use the Connection, see the zbus library.

    use std::error::Error;
    use systemdzbus::{ManagerProxy, Connection, SystemCtlBuilder};

    async fn example_get_units_manager_proxy() -> Result<(), Box::<dyn Error>> {
       /// Create zbus connection. You can also use Connection::session() here.
       let connection = Connection::system().await?;

       /// Create proxy per zbus
       let proxy = ManagerProxy::new(&connection).await?;

       /// Use the methods on the proxy. These are the ones
       /// that are actually documented here
       let units_raw = proxy.list_units().await?;

       assert!(!units_raw.is_empty());

       /// Or you can still have your connection managed, but still have direct access to
       /// manager.
       let systemctl = SystemCtlBuilder::new().init().await?;

       let manager = systemctl.get_manager_proxy();

       let units_raw = manager.list_units().await?;

       assert!(!units_raw.is_empty());

       Ok(())
   }

§D-Bus interface proxy for: org.freedesktop.systemd1.Manager

In terms of the ManagerProxy: This code was generated by zbus-xmlgen 5.1.0 from D-Bus introspection data. Source: Interface '/org/freedesktop/systemd1' from service 'org.freedesktop.systemd1' on system bus.

More information can be found in the Writing a client proxy section of the zbus documentation.

This type implements the D-Bus standard interfaces, (org.freedesktop.DBus.*) for which the following zbus API can be used:

Re-exports§

pub use manager::ManagerProxy;
pub use systemctl::job::Job;
pub use systemctl::systemctl_async::SystemCtlBuilder;
pub use systemctl::systemctl_blocking::SystemCtlBlockingBuilder;
pub use systemctl::unit::Unit;
pub use systemctl::unit::UnitActiveState;
pub use systemctl::unit::UnitChangeKind;
pub use systemctl::unit::UnitEnablementChange;
pub use systemctl::unit::UnitEnablementResponse;
pub use systemctl::unit::UnitLoadState;
pub use systemctl::unit::UnitMode;
pub use systemctl::unit_file::EnablementStatus;
pub use systemctl::unit_file::UnitFile;

Modules§

errors
manager
D-Bus interface proxy for: org.freedesktop.systemd1.Manager
systemctl
Main service in this crate

Structs§

Connection
A D-Bus connection.
OwnedObjectPath
Owned ObjectPath