You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
980 B
44 lines
980 B
5 years ago
|
use std::process::Command;
|
||
|
|
||
|
use crate::result::Result;
|
||
|
|
||
|
#[derive(Clone, Debug, Deserialize)]
|
||
|
pub struct App {
|
||
|
pub name: String,
|
||
|
pub command: String,
|
||
|
pub args: Vec<String>,
|
||
|
pub restart_on_success: Option<bool>,
|
||
|
pub restart_on_failure: Option<bool>,
|
||
|
pub restart_on_terminate: Option<bool>,
|
||
|
pub wait: Option<bool>,
|
||
|
pub hold: Option<bool>,
|
||
|
}
|
||
|
|
||
|
impl App {
|
||
|
pub fn wait_start(&self) -> Result<()> {
|
||
|
info!("starting application {}", &self.name);
|
||
|
|
||
|
let mut command = Command::new(&self.command);
|
||
|
command.args(&self.args);
|
||
|
|
||
|
match command.output() {
|
||
|
Ok(output) => {
|
||
|
if !output.stdout.is_empty() {
|
||
|
let s = String::from_utf8(output.stdout)?;
|
||
|
for line in s.lines() {
|
||
|
info!("[{}] stdout: {}", &self.name, line);
|
||
|
}
|
||
|
}
|
||
|
if !output.stderr.is_empty() {
|
||
|
let s = String::from_utf8(output.stderr)?;
|
||
|
for line in s.lines() {
|
||
|
info!("[{}] stderr: {}", &self.name, line);
|
||
|
}
|
||
|
}
|
||
|
Ok(())
|
||
|
}
|
||
|
Err(e) => Err(Box::from(e)),
|
||
|
}
|
||
|
}
|
||
|
}
|