From 2bbae7416274ef83a6b1d0f9e6101814f0d15ad1 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Thu, 5 Mar 2026 17:42:02 +0000 Subject: scripts: add debug-execution and deploy debug-execution: inspect a failed execution by ID prefix from prod DB. deploy: build and restart the claudomator systemd service. Co-Authored-By: Claude Sonnet 4.6 --- scripts/debug-execution | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ scripts/deploy | 26 ++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100755 scripts/debug-execution create mode 100755 scripts/deploy (limited to 'scripts') diff --git a/scripts/debug-execution b/scripts/debug-execution new file mode 100755 index 0000000..eba5c0a --- /dev/null +++ b/scripts/debug-execution @@ -0,0 +1,72 @@ +#!/usr/bin/env bash +# debug-execution: Show details for a failed task execution from the production DB. +# Usage: ./scripts/debug-execution +# Example: ./scripts/debug-execution c74c877f + +set -euo pipefail + +DB="/site/doot.terst.org/data/claudomator.db" +PREFIX="${1:?Usage: $0 }" + +if [[ ! -f "$DB" ]]; then + echo "ERROR: DB not found at $DB" >&2 + exit 1 +fi + +# Look up execution +ROW=$(sqlite3 "$DB" " + SELECT id, task_id, exit_code, status, stdout_path, stderr_path, error_msg + FROM executions + WHERE id LIKE '${PREFIX}%' + ORDER BY start_time DESC + LIMIT 1; +") + +if [[ -z "$ROW" ]]; then + echo "ERROR: No execution found matching '${PREFIX}'" >&2 + exit 1 +fi + +IFS='|' read -r EXEC_ID TASK_ID EXIT_CODE STATUS STDOUT_PATH STDERR_PATH ERROR_MSG <<< "$ROW" + +echo "=== Execution ===" +echo " ID: $EXEC_ID" +echo " Status: $STATUS" +echo " Exit code: $EXIT_CODE" +echo " Error: ${ERROR_MSG:-(none)}" + +# Look up task +TASK_ROW=$(sqlite3 "$DB" " + SELECT name, json_extract(config_json, '$.working_dir'), json_extract(config_json, '$.model') + FROM tasks + WHERE id = '${TASK_ID}'; +") + +if [[ -n "$TASK_ROW" ]]; then + IFS='|' read -r TASK_NAME WORKING_DIR MODEL <<< "$TASK_ROW" + echo "" + echo "=== Task ===" + echo " ID: $TASK_ID" + echo " Name: $TASK_NAME" + echo " Model: ${MODEL:-(not set)}" + echo " Working dir: ${WORKING_DIR:-(not set)}" +fi + +# Logs +print_log() { + local label="$1" path="$2" + echo "" + echo "=== $label ===" + if [[ -z "$path" ]]; then + echo " (path not recorded)" + elif [[ ! -f "$path" ]]; then + echo " (file not found: $path)" + elif [[ ! -s "$path" ]]; then + echo " (empty)" + else + tail -n 50 "$path" + fi +} + +print_log "stdout (last 50 lines)" "$STDOUT_PATH" +print_log "stderr (last 50 lines)" "$STDERR_PATH" diff --git a/scripts/deploy b/scripts/deploy new file mode 100755 index 0000000..a17b1ab --- /dev/null +++ b/scripts/deploy @@ -0,0 +1,26 @@ +#!/bin/bash +# deploy — Build and deploy claudomator to /site/doot.terst.org +# Usage: ./scripts/deploy +# Example: sudo ./scripts/deploy + +set -euo pipefail + +FQDN="doot.terst.org" +SITE_DIR="/site/${FQDN}" +BIN_DIR="${SITE_DIR}/bin" +SERVICE="claudomator@${FQDN}" +REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)" + +echo "==> Building claudomator..." +cd "${REPO_DIR}" +go build -o "${BIN_DIR}/claudomator" ./cmd/claudomator/ + +echo "==> Fixing permissions..." +chown www-data:www-data "${BIN_DIR}/claudomator" +chmod +x "${BIN_DIR}/claudomator" + +echo "==> Restarting service..." +systemctl restart "${SERVICE}" +systemctl status "${SERVICE}" --no-pager -l + +echo "==> Done!" -- cgit v1.2.3