aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2022-04-17 15:41:18 -0500
committerToby Vincent <tobyv13@gmail.com>2022-04-17 15:41:18 -0500
commit8c79a65b888db858157dfa612279a15fc7b2137a (patch)
treeeb9a68867623b2559b5360881a4243fa1300a194
parenta601e8b157280bf4cb457c3cfc586796a7989f8f (diff)
feat: impl running specific commands
-rw-r--r--zone_nspawn/src/nspawn.rs22
-rw-r--r--zoned/src/http.rs4
2 files changed, 17 insertions, 9 deletions
diff --git a/zone_nspawn/src/nspawn.rs b/zone_nspawn/src/nspawn.rs
index 3e4e095..017e5a3 100644
--- a/zone_nspawn/src/nspawn.rs
+++ b/zone_nspawn/src/nspawn.rs
@@ -44,15 +44,12 @@ impl NSpawn {
.ok_or_else(|| Error::NSpawn(format!("Failed to create container: {:?}", self)))
}
- pub async fn spawn<O, C, S>(
- opts: O,
- cmd: C,
- kill_rx: UnboundedReceiver<()>,
- ) -> Result<PtyMaster>
+ async fn spawn<O, S, C, A>(opts: O, cmd: C, kill_rx: UnboundedReceiver<()>) -> Result<PtyMaster>
where
O: IntoIterator<Item = S>,
- C: IntoIterator<Item = S>,
S: AsRef<OsStr>,
+ C: IntoIterator<Item = A>,
+ A: AsRef<OsStr>,
{
let base_opts = ["--quiet", "--wait", "--collect", "--service-type=exec"];
@@ -79,13 +76,22 @@ impl NSpawn {
Self::spawn(opts, cmd, kill_rx).await
}
- pub async fn run(&self, name: String, kill_rx: UnboundedReceiver<()>) -> Result<PtyMaster> {
+ pub async fn run<C, S>(
+ &self,
+ name: String,
+ cmd: C,
+ kill_rx: UnboundedReceiver<()>,
+ ) -> Result<PtyMaster>
+ where
+ C: IntoIterator<Item = S>,
+ S: AsRef<OsStr>,
+ {
let opts = [
&format!("{}={}", "--machine", name),
"--pty",
"--send-sighup",
];
- let cmd = ["/usr/bin/login", "-H", "-f", "root"];
+
Self::spawn(opts, cmd, kill_rx).await
}
diff --git a/zoned/src/http.rs b/zoned/src/http.rs
index b3d5149..dda3296 100644
--- a/zoned/src/http.rs
+++ b/zoned/src/http.rs
@@ -7,7 +7,9 @@ use axum::{
};
use std::{process::Command, sync::Arc};
use tracing::{info, instrument, warn};
-use zone_core::{CloneOptions, Container, ContainerOptions, ContainerStatus, FilterContainer, WebSocketOptions};
+use zone_core::{
+ CloneOptions, Container, ContainerOptions, ContainerStatus, FilterContainer, WebSocketOptions,
+};
use crate::{ws, Error, Result, State};