Files
cds-ai/atvm/watcher-service/start-atvm-run.sh
anthony.wen 9673d769e2 fix atvm watcher-backed run launch sequence
Execute the template step before starting watcher-backed ATVM runs.

- run --template-command synchronously in start-atvm-run.sh
- write template output to /tmp/<build>.launch.log
- stop before watcher/runner startup if template generation fails
- document the corrected wrapper behavior in watcher-service docs
- record the stale specPattern failure mode in automation run learnings
2026-04-29 12:14:55 -04:00

152 lines
3.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
usage() {
cat <<'EOF'
Usage:
start-atvm-run.sh --build-name <name> --runner-command <text> [options]
Options:
--build-name <name>
--template <name>
--template-command <text>
--runner-command <text>
--config-family <name>
--config-file <path>
--migration-style <text>
--integration-plugin <text>
--extra-option <text> Repeatable
--scope-description <text>
--categorize
--workdir <path> Default: /root/cdc-e2e-cyp-12.17.4
--log-path <path> Default: /tmp/<build-name>.log
--state-root <path> Default: /var/lib/atvm-run-watcher
EOF
}
BUILD_NAME=""
TEMPLATE=""
TEMPLATE_COMMAND=""
RUNNER_COMMAND=""
CONFIG_FAMILY=""
CONFIG_FILE=""
MIGRATION_STYLE=""
INTEGRATION_PLUGIN=""
EXTRA_OPTIONS=()
SCOPE_DESCRIPTION=""
WATCHER_CATEGORIZED="false"
RUNNER_WORKDIR="/root/cdc-e2e-cyp-12.17.4"
RUNNER_LOG=""
LAUNCH_LOG=""
STATE_ROOT="/var/lib/atvm-run-watcher"
while [[ $# -gt 0 ]]; do
case "$1" in
--build-name) BUILD_NAME="${2:-}"; shift 2 ;;
--template) TEMPLATE="${2:-}"; shift 2 ;;
--template-command) TEMPLATE_COMMAND="${2:-}"; shift 2 ;;
--runner-command) RUNNER_COMMAND="${2:-}"; shift 2 ;;
--config-family) CONFIG_FAMILY="${2:-}"; shift 2 ;;
--config-file) CONFIG_FILE="${2:-}"; shift 2 ;;
--migration-style) MIGRATION_STYLE="${2:-}"; shift 2 ;;
--integration-plugin) INTEGRATION_PLUGIN="${2:-}"; shift 2 ;;
--extra-option) EXTRA_OPTIONS+=("${2:-}"); shift 2 ;;
--scope-description) SCOPE_DESCRIPTION="${2:-}"; shift 2 ;;
--categorize) WATCHER_CATEGORIZED="true"; shift ;;
--workdir) RUNNER_WORKDIR="${2:-}"; shift 2 ;;
--log-path) RUNNER_LOG="${2:-}"; shift 2 ;;
--state-root) STATE_ROOT="${2:-}"; shift 2 ;;
-h|--help) usage; exit 0 ;;
*) echo "Unknown argument: $1" >&2; usage >&2; exit 1 ;;
esac
done
if [[ -z "$BUILD_NAME" ]]; then
echo "--build-name is required" >&2
usage >&2
exit 1
fi
if [[ -z "$RUNNER_COMMAND" ]]; then
echo "--runner-command is required" >&2
usage >&2
exit 1
fi
if [[ -z "$RUNNER_LOG" ]]; then
RUNNER_LOG="/tmp/${BUILD_NAME}.log"
fi
LAUNCH_LOG="/tmp/${BUILD_NAME}.launch.log"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
watcher_cmd=(
"${SCRIPT_DIR}/start-atvm-run-watcher.sh"
--build-name "${BUILD_NAME}"
--template "${TEMPLATE}"
--template-command "${TEMPLATE_COMMAND}"
--runner-command "${RUNNER_COMMAND}"
--config-family "${CONFIG_FAMILY}"
--config-file "${CONFIG_FILE}"
--migration-style "${MIGRATION_STYLE}"
--integration-plugin "${INTEGRATION_PLUGIN}"
--state-root "${STATE_ROOT}"
)
for option in "${EXTRA_OPTIONS[@]}"; do
watcher_cmd+=(--extra-option "${option}")
done
if [[ -n "${SCOPE_DESCRIPTION}" ]]; then
watcher_cmd+=(--scope-description "${SCOPE_DESCRIPTION}")
fi
if [[ "${WATCHER_CATEGORIZED}" == "true" ]]; then
watcher_cmd+=(--categorize)
fi
runner_cmd=(
"${SCRIPT_DIR}/start-atvm-runner.sh"
--build-name "${BUILD_NAME}"
--runner-command "${RUNNER_COMMAND}"
--workdir "${RUNNER_WORKDIR}"
--log-path "${RUNNER_LOG}"
--state-root "${STATE_ROOT}"
)
mkdir -p "$(dirname "${LAUNCH_LOG}")"
: > "${LAUNCH_LOG}"
if [[ -n "${TEMPLATE_COMMAND}" ]]; then
{
echo "Running template command:"
echo "${TEMPLATE_COMMAND}"
echo
} >>"${LAUNCH_LOG}"
if ! (
cd "${RUNNER_WORKDIR}"
bash -lc "${TEMPLATE_COMMAND}"
) >>"${LAUNCH_LOG}" 2>&1; then
echo "Template command failed for ${BUILD_NAME}. See ${LAUNCH_LOG}" >&2
exit 1
fi
fi
"${watcher_cmd[@]}"
for _ in {1..15}; do
if systemctl is-active --quiet "atvm-run-watcher@${BUILD_NAME}.service"; then
break
fi
sleep 1
done
if ! systemctl is-active --quiet "atvm-run-watcher@${BUILD_NAME}.service"; then
echo "Watcher service did not become active for ${BUILD_NAME}" >&2
exit 1
fi
"${runner_cmd[@]}"