37 lines
765 B
Rust
37 lines
765 B
Rust
use std::fs;
|
|
use serde::Deserialize;
|
|
use toml;
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Service {
|
|
pub name: String,
|
|
pub start: Start,
|
|
pub stop: Option<Stop>,
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Start {
|
|
pub command: String,
|
|
pub args: Vec<String>
|
|
}
|
|
|
|
#[derive(Deserialize, Debug)]
|
|
pub struct Stop {
|
|
pub command: String,
|
|
pub args: Vec<String>
|
|
}
|
|
|
|
pub fn get_services() -> Vec<Service> {
|
|
let mut services = Vec::new();
|
|
let paths = fs::read_dir("/etc/mini/").unwrap();
|
|
|
|
for path in paths {
|
|
// TODO: check ext
|
|
let svc_file_contents = fs::read_to_string(path.unwrap().path()).unwrap();
|
|
let svc : Service = toml::from_str(&svc_file_contents).unwrap();
|
|
services.push(svc);
|
|
}
|
|
|
|
services
|
|
}
|