use crate::Result;
use crate::cli::supervisor::{KillOrStopOutcome, resolve_existing_supervisor};
use crate::supervisor::SUPERVISOR;
#[derive(Debug, clap::Args)]
pub struct Run {
#[clap(short, long)]
force: bool,
#[clap(long)]
boot: bool,
#[clap(long, env = "PITCHFORK_CONTAINER")]
container: bool,
#[clap(long, env = "PITCHFORK_WEB_PORT")]
web_port: Option<u16>,
#[clap(long, env = "PITCHFORK_WEB_PATH")]
web_path: Option<String>,
}
impl Run {
pub async fn run(&self) -> Result<()> {
let (existing_pid, outcome) = resolve_existing_supervisor(self.force).await?;
match outcome {
KillOrStopOutcome::StillRunning => {
let pid = existing_pid.expect("StillRunning implies a pid exists");
warn!(
"Pitchfork supervisor is already running with pid {pid}. Use `--force` to replace it."
);
return Ok(());
}
KillOrStopOutcome::Killed => {
let pid = existing_pid.expect("Killed implies a pid exists");
info!("Killed existing supervisor with pid {pid}");
}
KillOrStopOutcome::AlreadyDead => {}
}
SUPERVISOR
.start(
self.boot,
self.container,
self.web_port,
self.web_path.clone(),
)
.await
}
}