Something went wrong. Try again.
bayes for days
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293#!/usr/bin/env bash# Kill the match containers this worktree started, and nobody else's.## `sds clean` kills every sds-* container on the machine, which is why# CLAUDE.md forbids running it while somebody else's benchmark is going. This# is the narrow version: a container is ours when its /work bind mount points# at our own worktree, which is how `sds bench` launches it. Containers# belonging to other worktrees are listed and left alone.## Usage:# scripts/kill-my-containers.sh # kill ours, report the rest# scripts/kill-my-containers.sh --dry-run # say what would happen# scripts/kill-my-containers.sh --worktree DIRset -euo pipefail
dry_run=0worktree=""
while [ $# -gt 0 ]; do case "$1" in --dry-run) dry_run=1; shift ;; --worktree) worktree="${2:-}"; shift 2 ;; -h | --help) sed -n '2,14p' "$0" | sed 's/^# \{0,1\}//'; exit 0 ;; *) echo "unknown argument: $1" >&2; exit 2 ;; esacdone
if ! command -v docker > /dev/null 2>&1; then echo "docker not found" >&2 exit 1fi
if [ -z "$worktree" ]; then worktree=$(git rev-parse --show-toplevel)fi# Resolve symlinks so the comparison against docker's own path is exact.worktree=$(cd "$worktree" && pwd -P)
echo "ours: $worktree"
mine=()theirs=()
while IFS= read -r name; do [ -n "$name" ] || continue source_dir=$( docker inspect "$name" \ --format '{{range .Mounts}}{{if eq .Destination "/work"}}{{.Source}}{{end}}{{end}}' \ 2> /dev/null || true ) if [ -z "$source_dir" ]; then # No /work mount is not something we can attribute, so we do not touch it. theirs+=("$name (no /work mount)") elif [ "$source_dir" = "$worktree" ]; then mine+=("$name") else theirs+=("$name <- $source_dir") fidone < <(docker ps --format '{{.Names}}' --filter name=sds- 2> /dev/null || true)
if [ ${#theirs[@]} -gt 0 ]; then echo echo "leaving ${#theirs[@]} container(s) that are not ours:" for entry in "${theirs[@]}"; do echo " $entry" donefi
if [ ${#mine[@]} -eq 0 ]; then echo echo "nothing of ours is running" exit 0fi
echoif [ "$dry_run" -eq 1 ]; then echo "would kill ${#mine[@]} container(s):" for name in "${mine[@]}"; do echo " $name" done exit 0fi
echo "killing ${#mine[@]} container(s):"for name in "${mine[@]}"; do if docker kill "$name" > /dev/null 2>&1; then echo " $name" else # A container that exited between the listing and the kill is not a failure. echo " $name (already gone)" fidone