diff --git a/src/commands/start.rs b/src/commands/start.rs index 08d42b11..2a10714f 100644 --- a/src/commands/start.rs +++ b/src/commands/start.rs @@ -2,11 +2,12 @@ use std::path::PathBuf; -use anyhow::{bail, Result}; +use anyhow::{bail, Context, Result}; use clap::Clap; use nix::unistd; use crate::container::{Container, ContainerStatus}; +use crate::hooks; use crate::notify_socket::{NotifySocket, NOTIFY_FILE}; #[derive(Clap, Debug)] @@ -39,8 +40,17 @@ impl Start { let mut notify_socket = NotifySocket::new(&container.root.join(NOTIFY_FILE)); notify_socket.notify_container_start()?; - container.update_status(ContainerStatus::Running).save()?; + + // Run post start hooks. It runs after the container process is started. + // It is called in the Runtime Namespace. + let spec_path = container.root.join("config.json"); + let spec = oci_spec::Spec::load(spec_path).context("failed to load spec")?; + if let Some(hooks) = spec.hooks.as_ref() { + hooks::run_hooks(hooks.poststart.as_ref(), Some(&container)) + .with_context(|| "Failed to run post start hooks")?; + } + Ok(()) } }