pub(crate) async fn prepare(self, sd: &Systemd) -> Result<PreparedService> {
        let dropin = Dropin::new(&self)
            .with_context(|| format!("while building dropin for {}", self.unit_name))?;

        let dropin_dir = Path::new("/run/systemd/system").join(format!("{}.d", &self.unit_name));
        std::fs::create_dir_all(&dropin_dir)
            .with_context(|| format!("while creating dropin dir {}", dropin_dir.display()))?;
        let dropin_file = OpenOptions::new()
            .create(true)
            .truncate(true)
            .write(true)
            .open(dropin_dir.join("99-metalos.conf"))
            .context("while creating dropin file")?;
        serde_systemd::to_writer(dropin_file, &dropin)?;

        if self.generator_path().exists() {
            let output =
                crate::generator::evaluate_generator(self.generator_path()).with_context(|| {
                    format!(
                        "while running generator at {}",
                        self.generator_path().display()
                    )
                })?;
            if let Some(dropin) = output.dropin {
                let dropin_path = dropin_dir.join("50-generator.conf");
                let dropin_file = OpenOptions::new()
                    .create(true)
                    .truncate(true)
                    .write(true)
                    .open(&dropin_path)
                    .with_context(|| {
                        format!(
                            "while creating generator dropin file ({})",
                            dropin_path.display()
                        )
                    })?;
                let dropin = crate::generator::GeneratedDropin::from(dropin);
                serde_systemd::to_writer(dropin_file, &dropin).with_context(|| {
                    format!(
                        "while serializing {:?} to generator dropin file ({})",
                        dropin,
                        dropin_path.display()
                    )
                })?;
            }
        }

        let unit_file = self.unit_file_path();
        // overwrite any existing link, since a different version of the service
        // could already be running
        sd.link_unit_files(&[systemd::FilePath::new(&unit_file)], true, true)
            .await
            .with_context(|| format!("while linking {}", unit_file.display()))?;
        Ok(PreparedService(self))
    }
/// Prepare this service version to be run the next time this service is
/// restarted. This method will not start the service, but it will link it.
/// A separate daemon-reload must be triggered for systemd to load the new
/// unit settings.
Prepare this service version to be run the next time this service is
restarted. This method will not start the service, but it will link it.
A separate daemon-reload must be triggered for systemd to load the new
unit settings.
Prepare this service version to be run the next time this service is restarted . This method will not start the service but it will link it . A separate daemon - reload must be triggered for systemd to load the new unit settings .
pub(crate) async fn prepare(self, sd: &Systemd) -> Result<PreparedService> {
        let dropin = Dropin::new(&self)
            .with_context(|| format!("while building dropin for {}", self.unit_name))?;
        let dropin_dir = Path::new("/run/systemd/system").join(format!("{}.d", &self.unit_name));
        std::fs::create_dir_all(&dropin_dir)
            .with_context(|| format!("while creating dropin dir {}", dropin_dir.display()))?;
        let dropin_file = OpenOptions::new()
            .create(true)
            .truncate(true)
            .write(true)
            .open(dropin_dir.join("99-metalos.conf"))
            .context("while creating dropin file")?;
        serde_systemd::to_writer(dropin_file, &dropin)?;
        if self.generator_path().exists() {
            let output =
                crate::generator::evaluate_generator(self.generator_path()).with_context(|| {
                    format!(
                        "while running generator at {}",
                        self.generator_path().display()
                    )
                })?;
            if let Some(dropin) = output.dropin {
                let dropin_path = dropin_dir.join("50-generator.conf");
                let dropin_file = OpenOptions::new()
                    .create(true)
                    .truncate(true)
                    .write(true)
                    .open(&dropin_path)
                    .with_context(|| {
                        format!(
                            "while creating generator dropin file ({})",
                            dropin_path.display()
                        )
                    })?;
                let dropin = crate::generator::GeneratedDropin::from(dropin);
                serde_systemd::to_writer(dropin_file, &dropin).with_context(|| {
                    format!(
                        "while serializing {:?} to generator dropin file ({})",
                        dropin,
                        dropin_path.display()
                    )
                })?;
            }
        }
        let unit_file = self.unit_file_path();
        // overwrite any existing link, since a different version of the service
        // could already be running
        sd.link_unit_files(&[systemd::FilePath::new(&unit_file)], true, true)
            .await
            .with_context(|| format!("while linking {}", unit_file.display()))?;
        Ok(PreparedService(self))
    }
pub ( crate ) async fn prepare ( self , sd : & Systemd ) -> Result < PreparedService > { let dropin = Dropin :: new ( & self ) . with_context ( | | format ! ( " " self unit_name ) ) ? ; let dropin_dir = Path :: new ( " " ) . join ( format ! ( " " self unit_name ) ) ; std :: fs :: create_dir_all ( & dropin_dir ) . with_context ( | | format ! ( " " dropin_dir display ( ) ) ) ? ; let dropin_file = OpenOptions :: new ( ) . create ( true ) . truncate ( true ) . write ( true ) . open ( dropin_dir . join ( " " ) ) . context ( " " ) ? ; serde_systemd :: to_writer ( dropin_file , & dropin ) ? ; if self . generator_path ( ) . exists ( ) { let output = crate :: generator :: evaluate_generator ( self . generator_path ( ) ) . with_context ( | | { format ! ( " " self generator_path ( ) display ( ) ) } ) ? ; if let Some ( dropin ) = output . dropin { let dropin_path = dropin_dir . join ( " " ) ; let dropin_file = OpenOptions :: new ( ) . create ( true ) . truncate ( true ) . write ( true ) . open ( & dropin_path ) . with_context ( | | { format ! ( " " dropin_path display ( ) ) } ) ? ; let dropin = crate :: generator :: GeneratedDropin :: from ( dropin ) ; serde_systemd :: to_writer ( dropin_file , & dropin ) . with_context ( | | { format ! ( " " dropin dropin_path display ( ) ) } ) ? ; } } let unit_file = self . unit_file_path ( ) ; // overwrite any existing link, since a different version of the service // could already be running sd . link_unit_files ( & [ systemd :: FilePath :: new ( & unit_file ) ] , true , true ) . await . with_context ( | | format ! ( " " unit_file display ( ) ) ) ? ; Ok ( PreparedService ( self ) ) }
Prepare this service version to be run the next time this service is
restarted.
Prepare this service version to be run the next time this service is restarted .
self
sd
&Systemd
self
sd
&Systemd