|
|
@@ -13,13 +13,12 @@ use tracing::info;
|
|
|
|
|
|
/// Builds the per-node remote stop command.
|
|
|
///
|
|
|
-/// `wait = true` (default): after `docker stop`, explicitly remove any
|
|
|
-/// stopped-but-still-present labeled containers (there is no `--rm`, so
|
|
|
-/// an Exited container lingers), then poll every 1 s (60 s max) until
|
|
|
-/// `docker ps` shows no labeled container running; if any remain, exit 1 —
|
|
|
-/// `run_ssh` surfaces that as an error. Without the explicit removal and
|
|
|
-/// the running-only polling, a graceful-shutdown straggler could keep the
|
|
|
-/// node reported as `occupied` for the immediately following serve.
|
|
|
+/// `wait = true` (default): after `docker stop`, poll until `docker ps` shows
|
|
|
+/// no container with the `sm121.recipe` / `sm121.cluster` labels in ANY state
|
|
|
+/// (running or exited-but-not-yet-removed) for 30 s, then explicitly `rm` the
|
|
|
+/// stragglers and poll running-only for another 30 s. Reporting success while
|
|
|
+/// any labeled container still existed is what made an immediately following
|
|
|
+/// `serve` see the node as `occupied` and bail out.
|
|
|
pub fn remote_command(recipe_name: &str, cluster_name: &str, rank: u32, wait: bool) -> String {
|
|
|
let filter = format!(
|
|
|
"--filter {} --filter {}",
|
|
|
@@ -28,15 +27,25 @@ pub fn remote_command(recipe_name: &str, cluster_name: &str, rank: u32, wait: bo
|
|
|
);
|
|
|
let wait_block = if wait {
|
|
|
"\
|
|
|
+for _ in $(seq 1 30); do \
|
|
|
+ n=$(docker ps -aq {filter}); \
|
|
|
+ [ -z \"$n\" ] && break; \
|
|
|
+ sleep 1; \
|
|
|
+done; \
|
|
|
docker ps -aq {filter} | xargs -r docker rm >/dev/null 2>&1; \
|
|
|
-for _ in $(seq 1 60); do \
|
|
|
+for _ in $(seq 1 30); do \
|
|
|
n=$(docker ps -q {filter}); \
|
|
|
[ -z \"$n\" ] && break; \
|
|
|
sleep 1; \
|
|
|
done; \
|
|
|
+n=$(docker ps -aq {filter}); \
|
|
|
+if [ -n \"$n\" ]; then \
|
|
|
+ echo \"sm121 stop: containers still present after wait: $n\" >&2; \
|
|
|
+ exit 1; \
|
|
|
+fi; \
|
|
|
n=$(docker ps -q {filter}); \
|
|
|
if [ -n \"$n\" ]; then \
|
|
|
- echo \"sm121 stop: containers still running after 60 s: $n\" >&2; \
|
|
|
+ echo \"sm121 stop: containers still running after wait: $n\" >&2; \
|
|
|
exit 1; \
|
|
|
fi; "
|
|
|
.to_string()
|
|
|
@@ -204,8 +213,8 @@ mod tests {
|
|
|
fn default_includes_verification_loop() {
|
|
|
let cmd = remote_command("r", "c", 0, true);
|
|
|
assert!(cmd.contains("xargs -r docker stop"));
|
|
|
+ assert!(cmd.contains("docker ps -aq"));
|
|
|
assert!(cmd.contains("xargs -r docker rm"));
|
|
|
- assert!(cmd.contains("seq 1 60"));
|
|
|
assert!(cmd.contains("exit 1"));
|
|
|
assert!(cmd.ends_with("true"));
|
|
|
}
|
|
|
@@ -213,7 +222,8 @@ mod tests {
|
|
|
#[test]
|
|
|
fn no_wait_omits_verification_loop() {
|
|
|
let cmd = remote_command("r", "c", 1, false);
|
|
|
- assert!(!cmd.contains("seq 1 60"));
|
|
|
+ assert!(!cmd.contains("seq 1 30"));
|
|
|
+ assert!(!cmd.contains("docker rm"));
|
|
|
assert!(!cmd.contains("exit 1"));
|
|
|
assert!(cmd.contains("/tmp/sm121_r_1"));
|
|
|
}
|