Skip to content

Commit

Permalink
restart modified host containers
Browse files Browse the repository at this point in the history
When a host container is running and its settings have changed,
bottlerocket will restart and apply new changes to this host container.
  • Loading branch information
gthao313 committed Sep 15, 2021
1 parent e723ddd commit 3bd666b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions sources/api/host-containers/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,15 @@ impl<'a> SystemdUnit<'a> {

Ok(())
}

fn try_reload_or_restart(&self) -> Result<()> {
command(
constants::SYSTEMCTL_BIN,
&["try-reload-or-restart", &self.unit],
)?;

Ok(())
}
}

/// Wrapper around process::Command that adds error checking.
Expand Down Expand Up @@ -402,8 +411,14 @@ where
// it will start before the system is fully configured
match command(constants::SYSTEMCTL_BIN, &["get-default"])?.trim().as_ref() {
"multi-user.target" => {
debug!("Enabling and starting container: '{}'", unit_name);
systemd_unit.enable_and_start()?
if systemd_unit.is_active()? {
debug!("Stopping and starting host container: '{}'", unit_name);
systemd_unit.try_reload_or_restart()?
}
else {
debug!("Enabling and starting container: '{}'", unit_name);
systemd_unit.enable_and_start()?
}
}
_ => {
debug!("Enabling: '{}'", unit_name);
Expand Down

0 comments on commit 3bd666b

Please sign in to comment.