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:
parent
f8a2f8007b
commit
cd34852f5d
1 changed files with 27 additions and 12 deletions
39
manage.sh
39
manage.sh
|
|
@ -196,21 +196,36 @@ case "$CMD" in
|
|||
|
||||
ingest-plex)
|
||||
PLEX_HOST="${1:-cass}"
|
||||
PLEX_LOG_PATH="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs/Plex Media Server.log"
|
||||
TMP_LOG="/tmp/turnstone-plex-$(date +%s).log"
|
||||
PLEX_LOG_DIR="/var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Logs"
|
||||
TMP_DIR="/tmp/turnstone-plex-$$"
|
||||
mkdir -p "$TMP_DIR"
|
||||
|
||||
info "Pulling Plex log from ${PLEX_HOST}…"
|
||||
if ! ssh "$PLEX_HOST" "cat '${PLEX_LOG_PATH}'" > "$TMP_LOG" 2>&1; then
|
||||
rm -f "$TMP_LOG"
|
||||
error "SSH to ${PLEX_HOST} failed. Ensure 'ssh ${PLEX_HOST}' works without a password prompt."
|
||||
info "Listing Plex logs on ${PLEX_HOST}…"
|
||||
# Get list of all rotated + active Plex logs
|
||||
mapfile -t REMOTE_LOGS < <(ssh "$PLEX_HOST" \
|
||||
"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
|
||||
LINES=$(wc -l < "$TMP_LOG")
|
||||
success "Pulled ${LINES} lines from ${PLEX_HOST}"
|
||||
|
||||
info "Ingesting into ${DB}…"
|
||||
"$PYTHON" scripts/ingest_corpus.py "$TMP_LOG" "$DB"
|
||||
rm -f "$TMP_LOG"
|
||||
success "Done. Restart the server to refresh: ./manage.sh restart"
|
||||
for remote_path in "${REMOTE_LOGS[@]}"; do
|
||||
# Plex Media Server.1.log → cass-plex_media_server.1.log
|
||||
local_name="${PLEX_HOST}-$(basename "$remote_path" | tr ' ' '_' | tr '[:upper:]' '[:lower:]')"
|
||||
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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue