Skip to content

Commit 93652b1

Browse files
committed
Copy executable to minions
1 parent 482ecd2 commit 93652b1

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

danny/src/config.rs

+35-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rand::rngs::StdRng;
33
use rand::RngCore;
44
use rand::SeedableRng;
55
use rand_xorshift::XorShiftRng;
6+
use std::path::PathBuf;
67
use std::{convert::TryFrom, time::Duration};
78
use std::{fmt::Debug, time::Instant};
89

@@ -227,6 +228,39 @@ impl Config {
227228
{
228229
if self.hosts.is_some() && self.process_id.is_none() {
229230
let exec = std::env::args().nth(0).unwrap();
231+
// first, we copy the executable to a known location, so that then we can run it
232+
let remote_exec = PathBuf::from("/tmp").join(
233+
PathBuf::from(&exec)
234+
.file_name()
235+
.unwrap_or_else(|| panic!("cannot get file name for {}", exec))
236+
);
237+
println!("Copying the executable to minions");
238+
let handles: Vec<std::process::Child> = self
239+
.hosts
240+
.as_ref()
241+
.unwrap()
242+
.hosts
243+
.iter()
244+
.map(|host| {
245+
let dest = format!(
246+
"{}:{}",
247+
host.name,
248+
remote_exec.to_str().expect("cannot convert path to string")
249+
);
250+
Command::new("rsync")
251+
.arg("--progress")
252+
.arg(&exec)
253+
.arg(dest)
254+
.spawn()
255+
.expect("problem spawning the rsync process")
256+
})
257+
.collect();
258+
259+
for mut h in handles {
260+
h.wait().expect("problem waiting for the rsync process");
261+
}
262+
263+
230264
info!("spawning executable {:?}", exec);
231265
// This is the top level invocation, which should spawn the processes with ssh
232266
let mut handles: Vec<std::process::Child> = self
@@ -241,7 +275,7 @@ impl Config {
241275
info!("Connecting to {}", host.name);
242276
Command::new("ssh")
243277
.arg(&host.name)
244-
.arg(&exec)
278+
.arg(&remote_exec)
245279
.arg(encoded_config)
246280
.spawn()
247281
.expect("problem spawning the ssh process")

0 commit comments

Comments
 (0)