prcs update

migrate
prplV 2025-05-23 16:16:03 +03:00
parent a4afd430af
commit 3f98fd7f24
2 changed files with 31 additions and 15 deletions

View File

@ -167,7 +167,7 @@ async fn process_cli_cmd(cli : Cli, params: Arc<PrebootParams>, global_config :
},
ConfigAction::Remote => {Ok(params.remote_server_url.clone())},
/* */
_ => Err(anyhow::Error::msg("Unrecognized command from CLI"))
// _ => Err(anyhow::Error::msg("Unrecognized command from CLI"))
}
},
/* */

View File

@ -10,6 +10,7 @@ use serde::Serialize;
pub mod v2 {
use log::info;
use tokio::time::sleep;
use crate::options::structs::DependencyType;
use std::path::Path;
@ -119,6 +120,7 @@ pub mod v2 {
"restart" => {
info!("Event on {} `{}` for {}. Restarting ...", dep_type, dep_name, self.name);
let _ = restart_process(&self.name, &self.bin).await;
sleep(Duration::from_millis(100)).await;
self.pid = Pid::new_from_output(get_pid(self.name.as_ref()).await);
info!("{}: New PID - {}", self.name, self.pid);
},
@ -126,6 +128,26 @@ pub mod v2 {
}
tokio::time::sleep(Duration::from_micros(100)).await;
}
pub async fn stop_by_user_call(&mut self) -> anyhow::Result<()> {
terminate_process(&self.name).await?;
self.state = ProcessState::StoppedByCli;
Ok(())
}
pub async fn freeze_by_user_call(&mut self) -> anyhow::Result<()> {
freeze_process(&self.name).await?;
self.state = ProcessState::HoldingByCli;
Ok(())
}
pub async fn start_by_user_call(&mut self) -> anyhow::Result<()> {
start_process(&self.name, &self.bin).await?;
self.state = ProcessState::Pending;
Ok(())
}
pub async fn unfreeze_by_user_call(&mut self) -> anyhow::Result<()> {
unfreeze_process(&self.name).await?;
self.state = ProcessState::Pending;
Ok(())
}
}
#[async_trait]
@ -298,14 +320,11 @@ pub async fn is_frozen(name: &str) -> bool {
///
/// *depends on* : -
///
pub async fn terminate_process(name: &str) {
pub async fn terminate_process(name: &str) -> anyhow::Result<()> {
let _ = Command::new("pkill")
.arg(name)
.output()
.unwrap_or_else(|_| {
error!("Failed to execute command 'pkill'");
std::process::exit(101);
});
.output()?;
Ok(())
}
/// # Fn `terminate_process`
@ -321,14 +340,11 @@ pub async fn terminate_process(name: &str) {
///
/// *depends on* : -
///
pub async fn freeze_process(name: &str) {
pub async fn freeze_process(name: &str) -> anyhow::Result<()> {
let _ = Command::new("pkill")
.args(["-STOP", name])
.output()
.unwrap_or_else(|_| {
error!("Failed to freeze process");
std::process::exit(101);
});
.output()?;
Ok(())
}
/// # Fn `unfreeze_process`
@ -365,7 +381,7 @@ pub async fn unfreeze_process(name: &str) -> anyhow::Result<()> {
/// *depends on* : fn `start_process`, fn `terminate_process`
///
pub async fn restart_process(name: &str, path: &str) -> anyhow::Result<()> {
terminate_process(name).await;
terminate_process(name).await?;
tokio::time::sleep(Duration::from_millis(100)).await;
start_process(name, path).await
}