#!/usr/bin/env bash # Stop every running match task and mark every unfinished match as over in # the API's store: ./scripts/matches/killall.sh # # The marking writes the sqlite file on the api host directly (WAL mode, so # the concurrent writer is safe) - the API has no admin surface for this, # deliberately, and this stays an operator's big red button. set -euo pipefail source "$(dirname "$0")/../lib/aws.sh" require_aws_credentials ENV_DIR="$(dirname "$0")/../../envs/lance.blue" CLUSTER="$(tofu -chdir="$ENV_DIR" output -raw match_cluster_name)" INSTANCE="$(tofu -chdir="$ENV_DIR" output -raw api_instance_id)" tasks="$(aws ecs list-tasks --cluster "$CLUSTER" --query 'taskArns[]' --output text | xargs)" failed=0 if [ -z "$tasks" ]; then echo "no running match tasks" else for task in $tasks; do aws ecs stop-task --cluster "$CLUSTER" --task "$task" \ --reason "killall: operator stop" --query 'task.taskArn' --output text \ || { echo "WARN: failed to stop task $task" >&2; failed=$((failed + 1)); } done [ "$failed" -eq 0 ] \ || echo "WARN: failed to stop $failed of $(wc -w <<<"$tasks") task(s); the rest were stopped" >&2 fi # AWS-StartNonInteractiveCommand rather than send-command's AWS-RunShellScript. # The same agent runs the same shell on the same host; what differs is the # subcommand used to ask. `aws ssm send-command` cannot run at all on a current # interpreter: one of its argument help strings carries a literal `%`, and # argparse in Python 3.14 expands every help string when the argument is # registered, so building the parser raises before an argument is read. It # fails with no arguments, and it fails on `help`. # # The output streams back over the session rather than being polled for, which # is also why there is no command id and no sleep. Both statements go in one # string because this document takes one command, not a list. sql="UPDATE matches SET status='over' WHERE status IN ('starting','running','ready'); SELECT 'marked over: ' || changes();" remote="command -v sqlite3 >/dev/null || dnf install -y -q sqlite sqlite3 /data/api/headquarters.sqlite \"$sql\"" parameters="$(jq -n --arg command "$remote" '{command: [$command]}')" aws ssm start-session --target "$INSTANCE" \ --document-name AWS-StartNonInteractiveCommand \ --parameters "$parameters" [ "$failed" -eq 0 ]