mirror of
https://github.com/huggingface/text-generation-inference.git
synced 2025-09-12 04:44:52 +00:00
more robust way of checking if is in container
This commit is contained in:
parent
713abb7073
commit
9fc54cd91c
@ -382,10 +382,10 @@ async fn main() -> Result<(), RouterError> {
|
||||
}
|
||||
};
|
||||
|
||||
// Only send usage stats when TGI is run in docker
|
||||
let is_docker = option_env!("DOCKER_LABEL").is_some();
|
||||
// Only send usage stats when TGI is run in container
|
||||
let is_container = usage_stats::is_container();
|
||||
|
||||
let user_agent = if !disable_usage_stats && is_docker {
|
||||
let user_agent = if !disable_usage_stats && is_container {
|
||||
let reduced_args = usage_stats::Args::new(
|
||||
config.clone(),
|
||||
tokenizer_class,
|
||||
|
@ -233,3 +233,21 @@ fn xpu_smi() -> Option<String> {
|
||||
let output = xpu_smi.replace('\n', "\n ");
|
||||
Some(output.trim().to_string())
|
||||
}
|
||||
|
||||
pub fn is_container() -> io::Result<bool> {
|
||||
let path = Path::new("/proc/self/cgroup");
|
||||
let file = File::open(&path)?;
|
||||
let reader = io::BufReader::new(file);
|
||||
|
||||
for line in reader.lines() {
|
||||
let line = line?;
|
||||
// Check for common container runtimes
|
||||
if line.contains("/docker/") || line.contains("/docker-") ||
|
||||
line.contains("/kubepods/") || line.contains("/kubepods-") ||
|
||||
line.contains("containerd") || line.contains("crio") ||
|
||||
line.contains("podman") {
|
||||
return Ok(true);
|
||||
}
|
||||
}
|
||||
Ok(false)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user