kanit

Toy init system
Log | Files | Refs | README | LICENSE

sysctl.rs (948B)


      1 use async_process::{Command, Stdio};
      2 use async_trait::async_trait;
      3 use log::info;
      4 
      5 use kanit_common::error::{Context, ErrorKind, Result, StaticError};
      6 use kanit_unit::{Dependencies, Unit};
      7 
      8 use crate::oneshot::Clock;
      9 use crate::unit_name;
     10 
     11 pub struct Sysctl;
     12 
     13 #[async_trait]
     14 impl Unit for Sysctl {
     15     unit_name!("sysctl");
     16 
     17     fn dependencies(&self) -> Dependencies {
     18         Dependencies::new().after(Clock.name()).clone()
     19     }
     20 
     21     async fn start(&mut self) -> Result<()> {
     22         info!("loading sysctl");
     23 
     24         let succ = Command::new("sysctl")
     25             .stdout(Stdio::null())
     26             .args(["-q", "--system"])
     27             .spawn()
     28             .context("failed to spawn sysctl")?
     29             .status()
     30             .await
     31             .context("failed to wait on sysctl")?
     32             .success();
     33 
     34         if !succ {
     35             Err(StaticError("failed load sysctl")).kind(ErrorKind::Recoverable)?;
     36         }
     37 
     38         Ok(())
     39     }
     40 }