#!/usr/bin/env bash # Read-only search for one request id in web, api, and caddy logs. set -euo pipefail set +x if [ $# -lt 1 ] || [ $# -gt 3 ]; then echo "usage: find-request-log.sh [--since 24h]" >&2 exit 2 fi request_id="$1" shift since="24h" while [ $# -gt 0 ]; do case "$1" in --since) since="${2:-}" shift 2 ;; *) echo "unknown argument" >&2 exit 2 ;; esac done [[ "$request_id" =~ ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$ ]] || { echo "requestId must be a UUID" >&2 exit 2 } [[ "$since" =~ ^[1-9][0-9]{0,3}[smhd]$ ]] || { echo "since must look like 24h" >&2 exit 2 } log_dir="${JYOTISHA_LOG_DIR:-}" if [ -n "$log_dir" ]; then [ -d "$log_dir" ] && [ ! -L "$log_dir" ] || { echo "log directory is unsafe" >&2 exit 1 } tmp="$(mktemp)" for service in web api caddy; do file="$log_dir/$service.log" [ -f "$file" ] && [ ! -L "$file" ] || continue grep -F -- "$request_id" "$file" >>"$tmp" || true done if [ -s "$tmp" ]; then grep -E '^[0-9]{4}-[0-9]{2}-[0-9]{2}T' "$tmp" | sort fi rm -f -- "$tmp" exit 0 fi compose_dir="${JYOTISHA_COMPOSE_DIR:-/opt/jyotisha-production}" export APP_ENV_FILE='../.env.production' export DATABASE_ENV_FILE='../.env.production.database' export CADDYFILE_PATH='./Caddyfile.production.selfhosted' export SITE_ADDRESS='https://jyotisha.chat' if [ -n "${JYOTISHA_COMPOSE_LOG_FIXTURE:-}" ]; then [ -f "$JYOTISHA_COMPOSE_LOG_FIXTURE" ] && [ ! -L "$JYOTISHA_COMPOSE_LOG_FIXTURE" ] || { echo "compose log fixture is missing" >&2 exit 1 } sed -E 's/^[^|]*\| //' "$JYOTISHA_COMPOSE_LOG_FIXTURE" | grep -F -- "$request_id" | grep -E '^[0-9]{4}-[0-9]{2}-[0-9]{2}T' | sort exit 0 fi sudo -n docker compose -p jyotisha-production \ --env-file "$compose_dir/.env.production" \ -f "$compose_dir/deploy/docker-compose.server.yml" \ -f "$compose_dir/deploy/docker-compose.postgres.yml" \ -f "$compose_dir/deploy/docker-compose.production.yml" \ logs --since "$since" --no-color --timestamps web api caddy | sed -E 's/^[^|]*\| //' | grep -F -- "$request_id" | grep -E '^[0-9]{4}-[0-9]{2}-[0-9]{2}T' | sort