libcontainer/container/container_resume.rs
1use libcgroups::common::{CgroupManager, FreezerState};
2
3use super::{Container, ContainerStatus};
4use crate::error::LibcontainerError;
5
6impl Container {
7 /// Resumes all processes within the container
8 ///
9 /// # Example
10 ///
11 /// ```no_run
12 /// use libcontainer::container::builder::ContainerBuilder;
13 /// use libcontainer::syscall::syscall::SyscallType;
14 ///
15 /// # fn main() -> anyhow::Result<()> {
16 /// let mut container = ContainerBuilder::new(
17 /// "74f1a4cb3801".to_owned(),
18 /// SyscallType::default(),
19 /// )
20 /// .as_init("/var/run/docker/bundle")
21 /// .build()?;
22 ///
23 /// container.resume()?;
24 /// # Ok(())
25 /// # }
26 /// ```
27 pub fn resume(&mut self) -> Result<(), LibcontainerError> {
28 self.refresh_status()?;
29 // check if container can be resumed :
30 // for example, a running process cannot be resumed
31 if !self.can_resume() {
32 tracing::error!(status = ?self.status(), id = ?self.id(), "cannot resume container");
33 return Err(LibcontainerError::IncorrectStatus(self.status()));
34 }
35
36 let cmanager =
37 libcgroups::common::create_cgroup_manager(libcgroups::common::CgroupConfig {
38 cgroup_path: self.spec()?.cgroup_path,
39 systemd_cgroup: self.systemd(),
40 container_name: self.id().to_string(),
41 })?;
42 // resume the frozen container
43 cmanager.freeze(FreezerState::Thawed)?;
44
45 tracing::debug!("saving running status");
46 self.set_status(ContainerStatus::Running).save()?;
47
48 tracing::debug!("container {} resumed", self.id());
49 Ok(())
50 }
51}