fix up the restart stuff so it actually restarts when configured to and not when not configured to

master
rascul 2 years ago
parent 5aec535c0e
commit 0fc873e965

@ -1,4 +1,4 @@
use std::process::{Command, ExitStatus};
use std::process::Command;
use colored::Colorize;
use log::{error, info};
@ -71,15 +71,4 @@ impl App {
Err(e) => Err(Box::from(e)),
}
}
/// see if the app should be restarted
pub fn check_restart(&self, status: ExitStatus) -> bool {
if status.success() {
self.restart_on_success
} else if let Some(_code) = status.code() {
self.restart_on_failure
} else {
self.restart_on_terminate
}
}
}

@ -129,31 +129,62 @@ fn run_loop(procs: Vec<Proc>, holds: Option<i8>, poll: Poll, signals: Signals) -
if code == 0 {
info!("[{}] exited successfully", &proc.app.name.yellow());
if proc.app.restart_on_failure {
if proc.app.restart_on_success {
if let Ok(p) = restart_app(&proc) {
poll.register(&p.process, p.token, Ready::all(), PollOpt::edge())
poll.register(
&p.process,
p.token,
Ready::all(),
PollOpt::edge(),
)
.unwrap();
procs.push(p);
procs.push(p);
} else if hold {
holds = Some(holds.unwrap_or(0) - 1);
}
}
} else {
info!("[{}] exited unsuccessfully with code {}", &proc.app.name.yellow(), code);
info!(
"[{}] exited unsuccessfully with code {}",
&proc.app.name.yellow(),
code
);
if proc.app.restart_on_failure {
if let Ok(p) = restart_app(&proc) {
poll.register(
&p.process,
p.token,
Ready::all(),
PollOpt::edge(),
)
.unwrap();
procs.push(p);
} else if hold {
holds = Some(holds.unwrap_or(0) - 1);
}
}
}
} else {
info!("[{}] was terminated", &proc.app.name.yellow());
}
if proc.app.check_restart(status) {
if let Ok(p) = restart_app(&proc) {
poll.register(&p.process, p.token, Ready::all(), PollOpt::edge())
if proc.app.restart_on_terminate {
if let Ok(p) = restart_app(&proc) {
poll.register(
&p.process,
p.token,
Ready::all(),
PollOpt::edge(),
)
.unwrap();
procs.push(p);
} else if hold {
holds = Some(holds.unwrap_or(0) - 1);
procs.push(p);
} else if hold {
holds = Some(holds.unwrap_or(0) - 1);
}
}
} else if hold {
}
if hold {
holds = Some(holds.unwrap_or(0) - 1);
}
}

Loading…
Cancel
Save