- update the watcher start helper to remove the old /tmp/<build-name>.log file before starting a fresh watcher instance for a reused build name - prevent the watcher from inheriting stale started_at timestamps from previous runs with the same build name and immediately exiting as HUNG - make reused-build watcher startup safer by resetting both watcher state and the matching temporary runner log
69 lines
1.9 KiB
Bash
69 lines
1.9 KiB
Bash
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
usage() {
|
|
cat <<'EOF'
|
|
Usage:
|
|
start-atvm-run-watcher.sh --build-name <name> [options]
|
|
|
|
Options:
|
|
--build-name <name>
|
|
--template <name>
|
|
--config-family <name>
|
|
--migration-style <text>
|
|
--integration-plugin <text>
|
|
--scope-description <text>
|
|
--categorize
|
|
--state-root <path> Default: /var/lib/atvm-run-watcher
|
|
EOF
|
|
}
|
|
|
|
BUILD_NAME=""
|
|
TEMPLATE=""
|
|
CONFIG_FAMILY=""
|
|
MIGRATION_STYLE=""
|
|
INTEGRATION_PLUGIN=""
|
|
SCOPE_DESCRIPTION=""
|
|
WATCHER_CATEGORIZED="false"
|
|
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 ;;
|
|
--config-family) CONFIG_FAMILY="${2:-}"; shift 2 ;;
|
|
--migration-style) MIGRATION_STYLE="${2:-}"; shift 2 ;;
|
|
--integration-plugin) INTEGRATION_PLUGIN="${2:-}"; shift 2 ;;
|
|
--scope-description) SCOPE_DESCRIPTION="${2:-}"; shift 2 ;;
|
|
--categorize) WATCHER_CATEGORIZED="true"; shift ;;
|
|
--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
|
|
|
|
RUN_DIR="${STATE_ROOT}/${BUILD_NAME}"
|
|
RUN_LOG="/tmp/${BUILD_NAME}.log"
|
|
systemctl stop "atvm-run-watcher@${BUILD_NAME}.service" >/dev/null 2>&1 || true
|
|
rm -rf "$RUN_DIR"
|
|
rm -f "$RUN_LOG"
|
|
mkdir -p "$RUN_DIR"
|
|
|
|
cat >"${RUN_DIR}/watch.env" <<EOF
|
|
ATVM_WATCHER_TEMPLATE=${TEMPLATE@Q}
|
|
ATVM_WATCHER_CONFIG_FAMILY=${CONFIG_FAMILY@Q}
|
|
ATVM_WATCHER_MIGRATION_STYLE=${MIGRATION_STYLE@Q}
|
|
ATVM_WATCHER_INTEGRATION_PLUGIN=${INTEGRATION_PLUGIN@Q}
|
|
ATVM_WATCHER_SCOPE_DESCRIPTION=${SCOPE_DESCRIPTION@Q}
|
|
ATVM_WATCHER_CATEGORIZED=${WATCHER_CATEGORIZED@Q}
|
|
EOF
|
|
|
|
systemctl start "atvm-run-watcher@${BUILD_NAME}.service"
|
|
systemctl status --no-pager "atvm-run-watcher@${BUILD_NAME}.service" || true
|