greentic_operator/services/
components.rs1use std::path::Path;
2
3use crate::services::runner::{ProcessStatus, ServiceState, log_path, pid_path, start_process};
4
5#[derive(Clone)]
6pub struct ComponentSpec {
7 pub id: String,
8 pub binary: String,
9 pub args: Vec<String>,
10}
11
12pub fn start_component(
13 root: &Path,
14 spec: &ComponentSpec,
15 envs: &[(&str, String)],
16) -> anyhow::Result<ServiceState> {
17 let pid = pid_path(root, &spec.id);
18 let log = log_path(root, &spec.id);
19 start_process(&spec.binary, &spec.args, envs, &pid, &log, Some(root))
20}
21
22pub fn stop_component(root: &Path, id: &str) -> anyhow::Result<ServiceState> {
23 let pid = pid_path(root, id);
24 super::runner::stop_process(&pid)
25}
26
27pub fn component_status(root: &Path, id: &str) -> anyhow::Result<ProcessStatus> {
28 let pid = pid_path(root, id);
29 super::runner::process_status(&pid)
30}