rc.rs (1061B)
1 use std::path::Path; 2 use std::process::Command; 3 4 use kanit_common::error::{Context, ErrorKind, Result, StaticError}; 5 6 pub fn initialize_rc() -> Result<()> { 7 if !Path::new("/etc/rc.start").exists() { 8 Err(StaticError("failed to find a start script")).kind(ErrorKind::Unrecoverable)?; 9 } 10 11 Command::new("/etc/rc.start") 12 .spawn() 13 .context("failed to start rc.start")?; 14 15 Ok(()) 16 } 17 18 pub fn teardown_rc() -> Result<()> { 19 if !Path::new("/etc/rc.stop").exists() { 20 Err(StaticError("failed to find a stop script")).kind(ErrorKind::Unrecoverable)?; 21 } 22 23 Command::new("/etc/rc.stop") 24 .spawn() 25 .context("failed to start rc.start")?; 26 27 Ok(()) 28 } 29 30 #[cfg(not(feature = "testing"))] 31 pub async fn event_rc(ev: Vec<u8>) -> Result<()> { 32 if !Path::new("/etc/rc.event").exists() { 33 return Ok(()); 34 } 35 36 Command::new("/etc/rc.event") 37 .arg(String::from_utf8_lossy(&ev).to_string()) 38 .spawn() 39 .context_kind("failed to start rc.event", ErrorKind::Recoverable)?; 40 41 Ok(()) 42 }