Skip to content

Commit 21af0f9

Browse files
authored
Merge pull request #20 from 51yu/port-zbus
port zbus
2 parents af28703 + 6663fe4 commit 21af0f9

21 files changed

+283
-2565
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
profile: minimal
2020
toolchain: stable
2121
override: true
22-
- name: Install lib
23-
run: sudo apt install libdbus-1-dev pkg-config
2422
- uses: actions-rs/cargo@v1
2523
with:
2624
command: check
@@ -34,8 +32,6 @@ jobs:
3432
profile: minimal
3533
toolchain: stable
3634
override: true
37-
- name: Install lib
38-
run: sudo apt install libdbus-1-dev pkg-config
3935
- uses: actions-rs/cargo@v1
4036
with:
4137
command: test
@@ -64,8 +60,6 @@ jobs:
6460
toolchain: stable
6561
override: true
6662
- run: rustup component add clippy
67-
- name: Install lib
68-
run: sudo apt install libdbus-1-dev pkg-config
6963
- uses: actions-rs/cargo@v1
7064
with:
7165
command: clippy

Cargo.toml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,22 @@
11
[package]
22
name = "systemd_client"
3-
version = "0.1.7"
3+
version = "0.2.0"
44
edition = "2021"
55
authors = ["Li Yu <li.yu.sh0211@gmail.com>"]
66
license = "Apache-2.0"
77
repository = "https://github.com/51yu/systemd-client"
88
homepage = "https://github.com/51yu/systemd-client"
99
documentation = "https://docs.rs/systemd-client/"
10-
description = "systemd client library implemented with dbus"
11-
keywords = ["systemd", "dbus"]
10+
description = "systemd client library implemented with zbus"
11+
keywords = ["systemd", "zbus"]
1212

1313
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1414

1515
[dependencies]
16-
dbus = { version = "0.9.5", features = ["futures"] }
17-
dbus-tokio = "0.7.5"
16+
zbus = { version = "2.0.1" }
17+
zvariant = "3.0.0"
1818
thiserror = "1.0.29"
19-
tokio = { version = "1.11.0", features = ["macros", "rt", "rt-multi-thread"] }
2019
tracing = "0.1"
2120

22-
[build-dependencies]
23-
anyhow = "1.0.51"
24-
dbus-codegen = "0.10.0"
25-
dbus = "0.9.5"
21+
[dev-dependencies]
22+
tokio = { version = "1.11.0", features = ["macros", "rt-multi-thread"] }

README.md

Lines changed: 26 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
# systemd-client
2-
[`systemd dbus`] client lib using [`dbus-codegen`]
2+
[`systemd dbus`] client lib using [`zbus`]
33
## Examples
44
### Blocking
55
list units
66
```rust
7-
use systemd_client::{
8-
build_blocking_client,
9-
manager::blocking::OrgFreedesktopSystemd1Manager,
10-
models::{IntoModel, Unit},
11-
Result, SystemdObjectType,
12-
};
7+
use systemd_client::{manager, models::Unit, Result};
138

149
fn main() -> Result<()> {
15-
let client = build_blocking_client(SystemdObjectType::Manager)?;
10+
let client = manager::build_blocking_proxy()?;
1611
let units = client.list_units()?;
1712
for unit in units {
18-
let unit: Unit = unit.into_model()?;
13+
let unit: Unit = unit.into();
1914
println!("{:#?}", unit);
2015
}
2116
Ok(())
@@ -24,10 +19,8 @@ fn main() -> Result<()> {
2419
create and start service
2520
```rust
2621
use systemd_client::{
27-
build_blocking_client, create_unit_configuration_file,
28-
manager::blocking::OrgFreedesktopSystemd1Manager, models::IntoModel,
29-
unit::blocking::UnitProperties, Result, ServiceConfiguration, ServiceUnitConfiguration,
30-
SystemdObjectType, UnitActiveStateType, UnitConfiguration, UnitLoadStateType, UnitProps,
22+
create_unit_configuration_file, manager, unit, Result, ServiceConfiguration,
23+
ServiceUnitConfiguration, UnitActiveStateType, UnitConfiguration, UnitLoadStateType, UnitProps,
3124
UnitSubStateType,
3225
};
3326

@@ -48,23 +41,23 @@ fn main() -> Result<()> {
4841
let svc_unit_literal = format!("{}", svc_unit);
4942
// create /etc/systemd/system/test.service
5043
create_unit_configuration_file("test.service", svc_unit_literal.as_bytes())?;
51-
let client = build_blocking_client(SystemdObjectType::Manager)?;
44+
let client = manager::build_blocking_proxy()?;
5245
let job_path = client.start_unit("test.service", "replace")?;
53-
println!("{}", job_path);
46+
println!("{}", job_path.as_str());
5447
let svc_unit_path = client.get_unit("test.service")?;
55-
println!("{}", svc_unit_path);
48+
println!("{}", svc_unit_path.as_str());
5649
// verify unit state given unit path
57-
let client = build_blocking_client(SystemdObjectType::Unit(svc_unit_path))?;
58-
let unit_props = client.get_unit_properties()?;
59-
let unit_props: UnitProps = unit_props.into_model()?;
50+
let client = unit::build_blocking_proxy(svc_unit_path)?;
51+
let unit_props = client.get_properties()?;
52+
let unit_props: UnitProps = unit_props.into();
6053
println!("{:?}", unit_props);
6154
assert_eq!(unit_props.load_state, UnitLoadStateType::Loaded);
6255
assert_eq!(unit_props.active_state, UnitActiveStateType::Active);
6356
assert_eq!(unit_props.sub_state, UnitSubStateType::Running);
6457
std::thread::sleep(std::time::Duration::from_secs(4));
6558
// service should exit after 3 sec
66-
let unit_props = client.get_unit_properties()?;
67-
let unit_props: UnitProps = unit_props.into_model()?;
59+
let unit_props = client.get_properties()?;
60+
let unit_props: UnitProps = unit_props.into();
6861
println!("{:?}", unit_props);
6962
assert_eq!(unit_props.load_state, UnitLoadStateType::Loaded);
7063
assert_eq!(unit_props.active_state, UnitActiveStateType::Inactive);
@@ -75,33 +68,24 @@ fn main() -> Result<()> {
7568
### Non Block
7669
list units
7770
```rust
78-
use systemd_client::{
79-
build_nonblock_client,
80-
manager::nonblock::OrgFreedesktopSystemd1Manager,
81-
models::{IntoModel, Unit},
82-
Result, SystemdObjectType,
83-
};
71+
use systemd_client::{manager, models::Unit, Result};
8472

8573
#[tokio::main]
8674
pub async fn main() -> Result<()> {
87-
let (client, jh) = build_nonblock_client(SystemdObjectType::Manager)?;
75+
let client = manager::build_nonblock_proxy().await?;
8876
let units = client.list_units().await?;
8977
for unit in units {
90-
let unit: Unit = unit.into_model()?;
78+
let unit: Unit = unit.into();
9179
println!("{:#?}", unit);
9280
}
93-
// close connection
94-
jh.abort();
9581
Ok(())
9682
}
9783
```
9884
create and start service
9985
```rust
10086
use systemd_client::{
101-
build_nonblock_client, create_unit_configuration_file,
102-
manager::nonblock::OrgFreedesktopSystemd1Manager, models::IntoModel,
103-
unit::nonblock::UnitProperties, Result, ServiceConfiguration, ServiceUnitConfiguration,
104-
SystemdObjectType, UnitActiveStateType, UnitConfiguration, UnitLoadStateType, UnitProps,
87+
create_unit_configuration_file, manager, unit, Result, ServiceConfiguration,
88+
ServiceUnitConfiguration, UnitActiveStateType, UnitConfiguration, UnitLoadStateType,
10589
UnitSubStateType,
10690
};
10791

@@ -123,41 +107,28 @@ async fn main() -> Result<()> {
123107
let svc_unit_literal = format!("{}", svc_unit);
124108
// create /etc/systemd/system/test.service
125109
create_unit_configuration_file("test.service", svc_unit_literal.as_bytes())?;
126-
let (client, jh) = build_nonblock_client(SystemdObjectType::Manager)?;
110+
let client = manager::build_nonblock_proxy().await?;
127111
let job_path = client.start_unit("test.service", "replace").await?;
128-
println!("{}", job_path);
112+
println!("{}", job_path.as_str());
129113
let svc_unit_path = client.get_unit("test.service").await?;
130-
println!("{}", svc_unit_path);
131-
// close connection
132-
jh.abort();
114+
println!("{}", svc_unit_path.as_str());
133115
// verify unit state given unit path
134-
let (client, jh) = build_nonblock_client(SystemdObjectType::Unit(svc_unit_path))?;
135-
let unit_props = client.get_unit_properties().await?;
136-
let unit_props: UnitProps = unit_props.into_model()?;
116+
let client = unit::build_nonblock_proxy(svc_unit_path).await?;
117+
let unit_props = client.get_properties().await?;
137118
println!("{:?}", unit_props);
138119
assert_eq!(unit_props.load_state, UnitLoadStateType::Loaded);
139120
assert_eq!(unit_props.active_state, UnitActiveStateType::Active);
140121
assert_eq!(unit_props.sub_state, UnitSubStateType::Running);
141122
std::thread::sleep(std::time::Duration::from_secs(4));
142123
// service should exit after 3 sec
143-
let unit_props = client.get_unit_properties().await?;
144-
let unit_props: UnitProps = unit_props.into_model()?;
124+
let unit_props = client.get_properties().await?;
145125
println!("{:?}", unit_props);
146126
assert_eq!(unit_props.load_state, UnitLoadStateType::Loaded);
147127
assert_eq!(unit_props.active_state, UnitActiveStateType::Inactive);
148128
assert_eq!(unit_props.sub_state, UnitSubStateType::Dead);
149-
// close connection
150-
jh.abort();
151129
Ok(())
152130
}
153131
```
154-
## Development
155-
### Install Tools
156-
```sh
157-
sudo apt install libdbus-1-dev pkg-config
158-
```
159-
### Codegen
160-
edit `build.rs` and create module for dbus object
161132

162133
[`systemd dbus`]: https://www.freedesktop.org/software/systemd/man/org.freedesktop.systemd1.html
163-
[`dbus-codegen`]: https://github.com/diwic/dbus-rs/tree/master/dbus-codegen
134+
[`zbus`]: https://gitlab.freedesktop.org/dbus/zbus

build.rs

Lines changed: 0 additions & 104 deletions
This file was deleted.

examples/list_units_blocking.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
use systemd_client::{
2-
build_blocking_client,
3-
manager::blocking::OrgFreedesktopSystemd1Manager,
4-
models::{IntoModel, Unit},
5-
Result, SystemdObjectType,
6-
};
1+
use systemd_client::{manager, models::Unit, Result};
72

83
fn main() -> Result<()> {
9-
let client = build_blocking_client(SystemdObjectType::Manager)?;
4+
let client = manager::build_blocking_proxy()?;
105
let units = client.list_units()?;
116
for unit in units {
12-
let unit: Unit = unit.into_model()?;
7+
let unit: Unit = unit.into();
138
println!("{:#?}", unit);
149
}
1510
Ok(())

examples/list_units_nonblock.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
use systemd_client::{
2-
build_nonblock_client,
3-
manager::nonblock::OrgFreedesktopSystemd1Manager,
4-
models::{IntoModel, Unit},
5-
Result, SystemdObjectType,
6-
};
1+
use systemd_client::{manager, models::Unit, Result};
72

83
#[tokio::main]
94
pub async fn main() -> Result<()> {
10-
let (client, jh) = build_nonblock_client(SystemdObjectType::Manager)?;
5+
let client = manager::build_nonblock_proxy().await?;
116
let units = client.list_units().await?;
127
for unit in units {
13-
let unit: Unit = unit.into_model()?;
8+
let unit: Unit = unit.into();
149
println!("{:#?}", unit);
1510
}
16-
// close connection
17-
jh.abort();
1811
Ok(())
1912
}

0 commit comments

Comments
 (0)