Prevent ATVM watcher and runner log race
This commit is contained in:
129
atvm/watcher-service/start-atvm-run.sh
Normal file
129
atvm/watcher-service/start-atvm-run.sh
Normal file
@@ -0,0 +1,129 @@
|
||||
#!/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=""
|
||||
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
|
||||
|
||||
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}"
|
||||
)
|
||||
|
||||
"${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[@]}"
|
||||
Reference in New Issue
Block a user