mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-19 07:14:22 +01:00
Merge pull request #5088 from liubin/fix/5087-force-shutdown-shim
runtime-rs: force shutdown shim process in it can't exit
This commit is contained in:
@@ -6,6 +6,9 @@
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use containerd_shim_protos::api;
|
||||
use kata_sys_util::spec::{get_bundle_path, get_contaier_type, load_oci_spec};
|
||||
use kata_types::container::ContainerType;
|
||||
use nix::{sys::signal::kill, sys::signal::SIGKILL, unistd::Pid};
|
||||
use protobuf::Message;
|
||||
use std::{fs, path::Path};
|
||||
|
||||
@@ -14,7 +17,7 @@ use crate::{shim::ShimExecutor, Error};
|
||||
impl ShimExecutor {
|
||||
pub async fn delete(&mut self) -> Result<()> {
|
||||
self.args.validate(true).context("validate")?;
|
||||
let rsp = self.do_cleanup().await.context("do cleanup")?;
|
||||
let rsp = self.do_cleanup().await.context("shim do cleanup")?;
|
||||
rsp.write_to_writer(&mut std::io::stdout())
|
||||
.context(Error::FileWrite(format!("write {:?} to stdout", rsp)))?;
|
||||
Ok(())
|
||||
@@ -41,9 +44,28 @@ impl ShimExecutor {
|
||||
info!(sl!(), "remote socket path: {:?}", &file_path);
|
||||
fs::remove_file(file_path).ok();
|
||||
}
|
||||
service::ServiceManager::cleanup(&self.args.id)
|
||||
.await
|
||||
.context("cleanup")?;
|
||||
|
||||
if let Err(e) = service::ServiceManager::cleanup(&self.args.id).await {
|
||||
error!(
|
||||
sl!(),
|
||||
"failed to cleanup in service manager: {:?}. force shutdown shim process", e
|
||||
);
|
||||
|
||||
let bundle_path = get_bundle_path().context("get bundle path")?;
|
||||
if let Ok(spec) = load_oci_spec() {
|
||||
if let Ok(ContainerType::PodSandbox) = get_contaier_type(&spec) {
|
||||
// only force shutdown for sandbox container
|
||||
if let Ok(shim_pid) = self.read_pid_file(&bundle_path) {
|
||||
info!(sl!(), "force to shutdown shim process {}", shim_pid);
|
||||
let pid = Pid::from_raw(shim_pid as i32);
|
||||
if let Err(_e) = kill(pid, SIGKILL) {
|
||||
// ignore kill errors
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(rsp)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user