-
-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathrun.rs
More file actions
64 lines (58 loc) · 1.8 KB
/
Copy pathrun.rs
File metadata and controls
64 lines (58 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::daemon::RunOptions;
use crate::ipc::client::IpcClient;
use crate::{env, Result};
use miette::bail;
/// Runs a one-off daemon
#[derive(Debug, clap::Args)]
#[clap(visible_alias = "r", verbatim_doc_comment)]
pub struct Run {
/// Name of the daemon to run
id: String,
#[clap(last = true)]
run: Vec<String>,
#[clap(short, long)]
force: bool,
/// Number of times to retry on error exit
#[clap(long, default_value = "0")]
retry: u32,
/// Delay in seconds before considering daemon ready (default: 3 seconds)
#[clap(short, long)]
delay: Option<u64>,
/// Wait until output matches this regex pattern before considering daemon ready
#[clap(short, long)]
output: Option<String>,
}
impl Run {
pub async fn run(&self) -> Result<()> {
info!("Running one-off daemon");
if self.run.is_empty() {
bail!("No command provided");
}
let ipc = IpcClient::connect(true).await?;
let (started, exit_code) = ipc
.run(RunOptions {
id: self.id.clone(),
cmd: self.run.clone(),
shell_pid: None,
force: self.force,
dir: env::CWD.clone(),
autostop: false,
cron_schedule: None,
cron_retrigger: None,
retry: self.retry,
retry_count: 0,
ready_delay: self.delay.or(Some(3)),
ready_output: self.output.clone(),
wait_ready: true,
})
.await?;
if !started.is_empty() {
info!("started {}", started.join(", "));
}
if let Some(code) = exit_code {
error!("Process exited with code {}", code);
std::process::exit(code);
}
Ok(())
}
}