fix: ingest-plex pulls all rotated logs and uses clean source IDs

- Pull all Plex Media Server*.log files (active + .1 through .5)
- Local filenames: cass-plex_media_server.N.log → source_id includes host
- mapfile for clean SSH list; separate ssh per file (no pipeline complexity)
- Auto-restart after ingest instead of prompting
This commit is contained in:
pyr0ball 2026-05-09 08:37:04 -07:00
parent f8a2f8007b
commit cd34852f5d

View file

@ -196,21 +196,36 @@ case "$CMD" in
ingest-plex) ingest-plex)
PLEX_HOST="${1:-cass}" PLEX_HOST="${1:-cass}"
PLEX_LOG_PATH="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log" PLEX_LOG_DIR="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs"
TMP_LOG="/tmp/turnstone-plex-$(date +%s).log" TMP_DIR="/tmp/turnstone-plex-$$"
mkdir -p "$TMP_DIR"
info "Pulling Plex log from ${PLEX_HOST}" info "Listing Plex logs on ${PLEX_HOST}"
if ! ssh "$PLEX_HOST" "cat '${PLEX_LOG_PATH}'" > "$TMP_LOG" 2>&1; then # Get list of all rotated + active Plex logs
rm -f "$TMP_LOG" mapfile -t REMOTE_LOGS < <(ssh "$PLEX_HOST" \
error "SSH to ${PLEX_HOST} failed. Ensure 'ssh ${PLEX_HOST}' works without a password prompt." "ls '${PLEX_LOG_DIR}'/Plex\ Media\ Server*.log 2>/dev/null") \
|| { rm -rf "$TMP_DIR"; error "SSH to ${PLEX_HOST} failed."; }
if [[ ${#REMOTE_LOGS[@]} -eq 0 ]]; then
rm -rf "$TMP_DIR"
error "No Plex logs found on ${PLEX_HOST} at ${PLEX_LOG_DIR}"
fi fi
LINES=$(wc -l < "$TMP_LOG")
success "Pulled ${LINES} lines from ${PLEX_HOST}"
info "Ingesting into ${DB}" for remote_path in "${REMOTE_LOGS[@]}"; do
"$PYTHON" scripts/ingest_corpus.py "$TMP_LOG" "$DB" # Plex Media Server.1.log → cass-plex_media_server.1.log
rm -f "$TMP_LOG" local_name="${PLEX_HOST}-$(basename "$remote_path" | tr ' ' '_' | tr '[:upper:]' '[:lower:]')"
success "Done. Restart the server to refresh: ./manage.sh restart" local_path="${TMP_DIR}/${local_name}"
info "$(basename "$remote_path")"
ssh "$PLEX_HOST" "cat '${remote_path}'" > "$local_path"
done
info "Ingesting ${#REMOTE_LOGS[@]} log file(s) into ${DB}"
for f in "$TMP_DIR"/*.log; do
"$PYTHON" scripts/ingest_corpus.py "$f" "$DB"
done
rm -rf "$TMP_DIR"
info "Done. Restarting server…"
exec bash "$0" restart
;; ;;
build-fts) build-fts)