summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKjetil Orbekk <kjetil.orbekk@gmail.com>2017-05-23 09:03:02 -0400
committerKjetil Orbekk <kjetil.orbekk@gmail.com>2017-05-23 09:03:02 -0400
commitb22fc3f433f91e1c893122794415f0f61f08e95c (patch)
tree17bf79a22cbffd44fe16f566fb8d5b07fcfb147c /src
parent42d1dcc48bfee8b0c33371861d3f4af72c13a1c3 (diff)
systemd: Very bad parsing of systemd jobs
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs5
-rw-r--r--src/systemd/job.rs24
-rw-r--r--src/systemd/mod.rs1
4 files changed, 32 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 75eacee..fa22112 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,3 +1,5 @@
+pub mod systemd;
+
#[cfg(test)]
mod tests {
#[test]
diff --git a/src/main.rs b/src/main.rs
index 368beb3..5f9009f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -82,7 +82,12 @@ fn hello(r: &mut Request) -> IronResult<Response> {
res
}
+extern crate systemhttp;
fn main() {
+ use systemhttp::systemd::job;
+ let u = job::get_jobs().unwrap();
+ println!("{:?}", u);
+
env_logger::init().unwrap();
let secret = b"secret2".to_vec();
let router = router!(
diff --git a/src/systemd/job.rs b/src/systemd/job.rs
new file mode 100644
index 0000000..68fb18d
--- /dev/null
+++ b/src/systemd/job.rs
@@ -0,0 +1,24 @@
+use std::collections::HashMap;
+use std::process::Command;
+
+use std::io;
+
+#[derive(Debug)]
+pub struct Unit {
+ name: String,
+ type_: String
+}
+
+pub fn get_jobs() -> io::Result<Vec<Unit>> {
+ let mut units = Vec::new();
+ let status = try!(Command::new("systemctl")
+ .args(&["show", "*"]).output());
+
+ for line in String::from_utf8_lossy(&status.stdout).split('\n') {
+ let words = line.split('=').collect::<Vec<&str>>();
+ if words.len() == 2 && words[0] == "Id" {
+ units.push(Unit { name: words[1].to_owned(), type_: "Unknown".to_owned() });
+ }
+ }
+ return Ok(units);
+}
diff --git a/src/systemd/mod.rs b/src/systemd/mod.rs
new file mode 100644
index 0000000..80daa3e
--- /dev/null
+++ b/src/systemd/mod.rs
@@ -0,0 +1 @@
+pub mod job;