1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
5#[serde(tag = "type")]
6pub enum Request {
7 Run {
8 command: String,
9 name: Option<String>,
10 cwd: Option<String>,
11 #[serde(default)]
12 env: Option<HashMap<String, String>>,
13 },
14 Stop { target: String },
15 StopAll,
16 Restart { target: String },
17 Status,
18 Logs {
19 target: Option<String>,
20 tail: usize,
21 follow: bool,
22 stderr: bool,
23 all: bool,
24 timeout_secs: Option<u64>,
25 #[serde(default)]
26 lines: Option<usize>,
27 },
28 Wait { target: String, until: Option<String>, regex: bool, exit: bool, timeout_secs: Option<u64> },
29 Shutdown,
30}
31
32#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
33#[serde(tag = "type")]
34pub enum Response {
35 Ok { message: String },
36 RunOk { name: String, id: String, pid: u32 },
37 Status { processes: Vec<ProcessInfo> },
38 LogLine { process: String, stream: Stream, line: String },
39 LogEnd,
40 WaitMatch { line: String },
41 WaitExited { exit_code: i32 },
42 WaitTimeout,
43 Error { code: i32, message: String },
44}
45
46#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
47pub struct ProcessInfo {
48 pub name: String,
49 pub id: String,
50 pub pid: u32,
51 pub state: ProcessState,
52 pub exit_code: Option<i32>,
53 pub uptime_secs: Option<u64>,
54 pub command: String,
55}
56
57#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
58#[serde(rename_all = "lowercase")]
59pub enum ProcessState { Running, Exited }
60
61#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
62#[serde(rename_all = "lowercase")]
63pub enum Stream { Stdout, Stderr }