mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 12:11:56 +00:00
Feat/stats (#2761)
* Feat: Add the memory for the stats. * Chore: Add %
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
use std::collections::BTreeSet;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::time::Duration;
|
||||
use std::{collections::BTreeSet, ffi::OsString};
|
||||
|
||||
use clap::builder::ValueParserFactory;
|
||||
use futures::{AsyncWriteExt, StreamExt};
|
||||
@@ -32,7 +32,7 @@ use crate::util::io::open_file;
|
||||
use crate::util::rpc_client::UnixRpcClient;
|
||||
use crate::util::{new_guid, Invoke};
|
||||
|
||||
#[cfg(feature = "dev")]
|
||||
// #[cfg(feature = "dev")]
|
||||
pub mod dev;
|
||||
|
||||
const LXC_CONTAINER_DIR: &str = "/var/lib/lxc";
|
||||
@@ -287,6 +287,30 @@ impl LxcContainer {
|
||||
self.rpc_bind.path()
|
||||
}
|
||||
|
||||
pub async fn command(&self, commands: &[&str]) -> Result<String, Error> {
|
||||
let mut cmd = Command::new("lxc-attach");
|
||||
cmd.kill_on_drop(true);
|
||||
|
||||
let output = cmd
|
||||
.arg(&**self.guid)
|
||||
.arg("--")
|
||||
.args(commands)
|
||||
.output()
|
||||
.await?;
|
||||
|
||||
if !output.status.success() {
|
||||
return Err(Error::new(
|
||||
eyre!(
|
||||
"Command failed with exit code: {:?} \n Message: {:?}",
|
||||
output.status.code(),
|
||||
String::from_utf8(output.stderr)
|
||||
),
|
||||
ErrorKind::Docker,
|
||||
));
|
||||
}
|
||||
Ok(String::from_utf8(output.stdout)?)
|
||||
}
|
||||
|
||||
#[instrument(skip_all)]
|
||||
pub async fn exit(mut self) -> Result<(), Error> {
|
||||
Command::new("lxc-stop")
|
||||
|
||||
Reference in New Issue
Block a user