Compare commits

..

No commits in common. "aabf39f0412309a122490801a0b5ccda62deeaf5" and "11e2a14cc4e9f29cfcd5298e149ebe1fb9c32df1" have entirely different histories.

6 changed files with 37 additions and 67 deletions

28
Cargo.lock generated
View File

@ -26,12 +26,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "anyhow"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
[[package]]
name = "autocfg"
version = "1.1.0"
@ -321,26 +315,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "thiserror"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9a7210f5c9a7156bb50aa36aed4c95afb51df0df00713949448cf9e97d382d2"
dependencies = [
"thiserror-impl",
]
[[package]]
name = "thiserror-impl"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "266b2e40bc00e5a6c09c3584011e08b06f123c00362c92b975ba9843aaaa14b8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "tokio"
version = "1.34.0"
@ -466,11 +440,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
name = "wingmate-rs"
version = "0.1.0"
dependencies = [
"anyhow",
"lazy_static",
"nix",
"regex",
"thiserror",
"tokio",
"tokio-util",
]

View File

@ -6,10 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.75"
lazy_static = "1.4.0"
nix = {version = "0.27.1", features = ["process", "signal", "fs"]}
regex = "1.10.2"
thiserror = "1.0.50"
tokio = { version = "1.34.0", features = ["full"] }
tokio-util = "0.7.10"

View File

@ -1 +1,3 @@
you cannot run this file
#!/bin/bash
exec sleep 1

View File

@ -42,7 +42,7 @@ pub struct Config {
impl Config {
pub fn find(search_path: Vec<String>) -> Result<Config, Box<dyn std_error::Error>> {
if search_path.is_empty() {
return Err(wingmate_error::WingmateInitError::InvalidConfigSearchPath.into());
return Err(wingmate_error::InvalidConfigSearchPathError.into());
}
let mut svc_commands: Vec<Command> = Vec::new();
@ -81,7 +81,7 @@ impl Config {
}
if svc_commands.is_empty() && cron.is_empty() {
return Err(wingmate_error::WingmateInitError::NoServiceOrCron.into());
return Err(wingmate_error::NoServiceOrCronFoundError.into());
}
let mut config = Config {

View File

@ -11,37 +11,30 @@ use nix::sys::signal::{kill, Signal};
use nix::errno::Errno;
use nix::unistd::Pid;
use crate::init::config;
use crate::init::error::{NoShellAvailableError, WingmateInitError};
use crate::init::error::NoShellAvailableError;
pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send + Sync>>>, cfg: &config::Config, cancel: CancellationToken)
-> Result<(), Box<dyn error::Error>> {
for svc_ in cfg.get_service_iter() {
let mut shell: String = String::new();
if let config::Command::ShellPrefixed(_) = svc_ {
shell = cfg.get_shell().ok_or::<Box<dyn error::Error>>(NoShellAvailableError.into())?;
}
let shell: String = cfg.get_shell().ok_or::<Box<dyn error::Error>>(NoShellAvailableError.into())?;
let svc = svc_.clone();
// if let config::Command::ShellPrefixed(_) = svc {
// shell = cfg.get_shell().ok_or::<Box<dyn error::Error>>(NoShellAvailableError.into())?;
// }
let cancel = cancel.clone();
ts.spawn(async move {
'autorestart: loop {
let mut child: Child;
let shell = shell.clone();
let svc = svc.clone();
match svc {
config::Command::Direct(c) => {
let exp_str = c.clone();
child = Command::new(c).spawn().map_err(|e| {
Box::new(WingmateInitError::SpawnError { source: e, message: exp_str })
})?;
child = Command::new(c).spawn().expect("change me");
},
config::Command::ShellPrefixed(s) => {
let shell = shell.clone();
let exp_str = s.clone();
let exp_shell = shell.clone();
child = Command::new(shell).arg(s).spawn().map_err(|e| {
Box::new(WingmateInitError::SpawnError { source: e, message: format!("{} {}", exp_shell, exp_str) })
})?;
child = Command::new(shell).arg(s).spawn().expect("change me");
}
}
@ -81,12 +74,12 @@ pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send +
},
}
}
dbg!("starter: task completed");
println!("starter: task completed");
Ok(())
});
}
dbg!("starter: spawning completed");
println!("starter: spawning completed");
Ok(())
}
@ -102,7 +95,8 @@ fn result_match(result: tokio_result<ExitStatus>) -> Result<(), Box<dyn error::E
}
}
dbg!("starter: sleep exited");
//TODO: remove me! this is for debug + tracing purpose
println!("starter: sleep exited");
Ok(())
}

View File

@ -1,25 +1,29 @@
use thiserror::Error;
use std::fmt;
use std::error;
#[derive(Debug, Clone)]
pub struct InvalidConfigSearchPathError;
#[derive(Error,Debug)]
pub enum WingmateInitError {
#[error("invalid config search path")]
InvalidConfigSearchPath,
#[error("no service or cron found")]
NoServiceOrCron,
#[error("failed to spawn: {}", message)]
SpawnError {
#[source]
source: std::io::Error,
message: String,
impl fmt::Display for InvalidConfigSearchPathError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "invalid config search path")
}
}
impl error::Error for InvalidConfigSearchPathError {}
#[derive(Debug,Clone)]
pub struct NoServiceOrCronFoundError;
impl fmt::Display for NoServiceOrCronFoundError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "no service or cron found")
}
}
impl error::Error for NoServiceOrCronFoundError {}
#[derive(Debug,Clone)]
pub struct CronSyntaxError(pub String);