Skip to content

Instantly share code, notes, and snippets.

@mizzy
Last active October 11, 2017 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mizzy/0210a1b8c56c1bf1411b1b8e310e90d8 to your computer and use it in GitHub Desktop.
Save mizzy/0210a1b8c56c1bf1411b1b8e310e90d8 to your computer and use it in GitHub Desktop.
extern crate dbus;
use dbus::{Connection, BusType, Message, Path};
use dbus::arg;
fn main() {
// Get object path by service name
let c = Connection::get_private(BusType::System).unwrap();
let m = Message::new_method_call("org.freedesktop.systemd1",
"/org/freedesktop/systemd1",
"org.freedesktop.systemd1.Manager",
"GetUnit")
.unwrap()
.append1("ssh.service");
let r = c.send_with_reply_and_block(m, 2000).unwrap();
let o: Path = r.read1().unwrap();
println!("{}", o);
// Get active state of the service
let m = Message::new_method_call("org.freedesktop.systemd1",
o,
"org.freedesktop.DBus.Properties",
"Get")
.unwrap()
.append2("org.freedesktop.systemd1.Unit", "ActiveState");
let r = c.send_with_reply_and_block(m, 2000).unwrap();
let s: arg::Variant<&str> = r.read1().unwrap();
println!("{}", s.0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment