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 {
15 target: String,
16 },
17 StopAll,
18 Restart {
19 target: String,
20 },
21 Status,
22 Logs {
23 target: Option<String>,
24 tail: usize,
25 follow: bool,
26 stderr: bool,
27 all: bool,
28 timeout_secs: Option<u64>,
29 #[serde(default)]
30 lines: Option<usize>,
31 },
32 Wait {
33 target: String,
34 until: Option<String>,
35 regex: bool,
36 exit: bool,
37 timeout_secs: Option<u64>,
38 },
39 Shutdown,
40}
41
42#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
43#[serde(tag = "type")]
44pub enum Response {
45 Ok {
46 message: String,
47 },
48 RunOk {
49 name: String,
50 id: String,
51 pid: u32,
52 },
53 Status {
54 processes: Vec<ProcessInfo>,
55 },
56 LogLine {
57 process: String,
58 stream: Stream,
59 line: String,
60 },
61 LogEnd,
62 WaitMatch {
63 line: String,
64 },
65 WaitExited {
66 exit_code: Option<i32>,
67 },
68 WaitTimeout,
69 Error {
70 code: i32,
71 message: String,
72 },
73}
74
75#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
76pub struct ProcessInfo {
77 pub name: String,
78 pub id: String,
79 pub pid: u32,
80 pub state: ProcessState,
81 pub exit_code: Option<i32>,
82 pub uptime_secs: Option<u64>,
83 pub command: String,
84}
85
86#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
87#[serde(rename_all = "lowercase")]
88pub enum ProcessState {
89 Running,
90 Exited,
91}
92
93#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
94#[serde(rename_all = "lowercase")]
95pub enum Stream {
96 Stdout,
97 Stderr,
98}