Compare commits
No commits in common. "aabf39f0412309a122490801a0b5ccda62deeaf5" and "11e2a14cc4e9f29cfcd5298e149ebe1fb9c32df1" have entirely different histories.
aabf39f041
...
11e2a14cc4
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -26,12 +26,6 @@ dependencies = [
|
|||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "anyhow"
|
|
||||||
version = "1.0.75"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "autocfg"
|
name = "autocfg"
|
||||||
version = "1.1.0"
|
version = "1.1.0"
|
||||||
@ -321,26 +315,6 @@ dependencies = [
|
|||||||
"unicode-ident",
|
"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]]
|
[[package]]
|
||||||
name = "tokio"
|
name = "tokio"
|
||||||
version = "1.34.0"
|
version = "1.34.0"
|
||||||
@ -466,11 +440,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
|||||||
name = "wingmate-rs"
|
name = "wingmate-rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"nix",
|
"nix",
|
||||||
"regex",
|
"regex",
|
||||||
"thiserror",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
"tokio-util",
|
"tokio-util",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -6,10 +6,8 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.75"
|
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
nix = {version = "0.27.1", features = ["process", "signal", "fs"]}
|
nix = {version = "0.27.1", features = ["process", "signal", "fs"]}
|
||||||
regex = "1.10.2"
|
regex = "1.10.2"
|
||||||
thiserror = "1.0.50"
|
|
||||||
tokio = { version = "1.34.0", features = ["full"] }
|
tokio = { version = "1.34.0", features = ["full"] }
|
||||||
tokio-util = "0.7.10"
|
tokio-util = "0.7.10"
|
||||||
|
|||||||
@ -1 +1,3 @@
|
|||||||
you cannot run this file
|
#!/bin/bash
|
||||||
|
|
||||||
|
exec sleep 1
|
||||||
@ -42,7 +42,7 @@ pub struct Config {
|
|||||||
impl Config {
|
impl Config {
|
||||||
pub fn find(search_path: Vec<String>) -> Result<Config, Box<dyn std_error::Error>> {
|
pub fn find(search_path: Vec<String>) -> Result<Config, Box<dyn std_error::Error>> {
|
||||||
if search_path.is_empty() {
|
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();
|
let mut svc_commands: Vec<Command> = Vec::new();
|
||||||
@ -81,7 +81,7 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if svc_commands.is_empty() && cron.is_empty() {
|
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 {
|
let mut config = Config {
|
||||||
|
|||||||
@ -11,37 +11,30 @@ use nix::sys::signal::{kill, Signal};
|
|||||||
use nix::errno::Errno;
|
use nix::errno::Errno;
|
||||||
use nix::unistd::Pid;
|
use nix::unistd::Pid;
|
||||||
use crate::init::config;
|
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)
|
pub fn start_services(ts: &mut JoinSet<Result<(), Box<dyn error::Error + Send + Sync>>>, cfg: &config::Config, cancel: CancellationToken)
|
||||||
-> Result<(), Box<dyn error::Error>> {
|
-> Result<(), Box<dyn error::Error>> {
|
||||||
|
|
||||||
for svc_ in cfg.get_service_iter() {
|
for svc_ in cfg.get_service_iter() {
|
||||||
let mut shell: String = String::new();
|
let shell: String = cfg.get_shell().ok_or::<Box<dyn error::Error>>(NoShellAvailableError.into())?;
|
||||||
if let config::Command::ShellPrefixed(_) = svc_ {
|
|
||||||
shell = cfg.get_shell().ok_or::<Box<dyn error::Error>>(NoShellAvailableError.into())?;
|
|
||||||
}
|
|
||||||
let svc = svc_.clone();
|
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();
|
let cancel = cancel.clone();
|
||||||
ts.spawn(async move {
|
ts.spawn(async move {
|
||||||
'autorestart: loop {
|
'autorestart: loop {
|
||||||
let mut child: Child;
|
let mut child: Child;
|
||||||
|
let shell = shell.clone();
|
||||||
let svc = svc.clone();
|
let svc = svc.clone();
|
||||||
match svc {
|
match svc {
|
||||||
config::Command::Direct(c) => {
|
config::Command::Direct(c) => {
|
||||||
let exp_str = c.clone();
|
child = Command::new(c).spawn().expect("change me");
|
||||||
child = Command::new(c).spawn().map_err(|e| {
|
|
||||||
Box::new(WingmateInitError::SpawnError { source: e, message: exp_str })
|
|
||||||
})?;
|
|
||||||
},
|
},
|
||||||
config::Command::ShellPrefixed(s) => {
|
config::Command::ShellPrefixed(s) => {
|
||||||
let shell = shell.clone();
|
child = Command::new(shell).arg(s).spawn().expect("change me");
|
||||||
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) })
|
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -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(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
dbg!("starter: spawning completed");
|
println!("starter: spawning completed");
|
||||||
|
|
||||||
Ok(())
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1,25 +1,29 @@
|
|||||||
use thiserror::Error;
|
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::error;
|
use std::error;
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct InvalidConfigSearchPathError;
|
||||||
|
|
||||||
#[derive(Error,Debug)]
|
impl fmt::Display for InvalidConfigSearchPathError {
|
||||||
pub enum WingmateInitError {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
#[error("invalid config search path")]
|
write!(f, "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 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)]
|
#[derive(Debug,Clone)]
|
||||||
pub struct CronSyntaxError(pub String);
|
pub struct CronSyntaxError(pub String);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user