From c39e70b430c353c96e42c65988fbabe5e34e6996 Mon Sep 17 00:00:00 2001 From: ChuckPa Date: Wed, 6 Nov 2024 20:59:00 -0500 Subject: [PATCH] Add Prune Delete all images and temporary transcoder files/dirs in "/tmp". --- DBRepair.sh | 97 ++++++++++++++++++++++++++++++++++++++++++++++++---- README.md | 4 ++- ReleaseNotes | 5 +++ 3 files changed, 99 insertions(+), 7 deletions(-) diff --git a/DBRepair.sh b/DBRepair.sh index 4bdd160..3fa189f 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -2,12 +2,12 @@ ######################################################################### # Plex Media Server database check and repair utility script. # # Maintainer: ChuckPa # -# Version: v1.08.00 # -# Date: 28-Aug-2024 # +# Version: v1.09.00 # +# Date: 06-Nov-2024 # ######################################################################### # Version for display purposes -Version="v1.08.00" +Version="v1.09.00" # Have the databases passed integrity checks CheckedDB=0 @@ -29,6 +29,10 @@ RemoveDuplicates=0 # Keep track of how many times the user's hit enter with no command (implied EOF) NullCommands=0 +# Default TMP dir for most hosts +TMPDIR="/tmp" +SYSTMP="/tmp" + # Global variable - main database CPPL=com.plexapp.plugins.library @@ -220,8 +224,8 @@ FreeSpaceAvailable() { SpaceNeeded=$((LibSize + BlobsSize)) # Compute need (minimum $Multiplier existing; current, backup, temp and room to write new) - SpaceNeeded="$(expr $SpaceNeeded '*' $Multiplier)" - SpaceNeeded="$(expr $SpaceNeeded / 1000000)" + SpaceNeeded=$((SpaceNeeded '*' $Multiplier)) + SpaceNeeded=$((SpaceNeeded / 1000000)) # If need < available, all good [ $SpaceNeeded -lt $SpaceAvailable ] && return 0 @@ -396,6 +400,8 @@ HostConfig() { CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" LOGFILE="$DBDIR/DBRepair.log" + TMPDIR="$AppSuppDir/Plex Media Server/tmp" + SYSTMP="$TMPDIR" # We are done HostType="Synology (DSM 7)" @@ -426,6 +432,8 @@ HostConfig() { CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" LOGFILE="$DBDIR/DBRepair.log" + TMPDIR="$AppSuppDir/Plex Media Server/tmp" + SYSTMP="$TMPDIR" HostType="Synology (DSM 6)" @@ -451,6 +459,8 @@ HostConfig() { CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" LOGFILE="$DBDIR/DBRepair.log" + TMPDIR="$AppSuppDir/tmp" + SYSTMP="$TMPDIR" # Start/Stop if [ -e /etc/init.d/plex.sh ]; then @@ -476,6 +486,8 @@ HostConfig() { DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases" LOGFILE="$DBDIR/DBRepair.log" LOG_TOOL="logger" + TMPDIR="/var/snap/plexmediaserver/common/tmp" + SYSTMP="$TMPDIR" HaveStartStop=1 StartCommand="snap start plexmediaserver" @@ -522,6 +534,8 @@ HostConfig() { HaveStartStop=1 StartCommand="systemctl start plexmediaserver" StopCommand="systemctl stop plexmediaserver" + TMPDIR="/tmp" + SYSTMP="$TMPDIR" return 0 # Netgear ReadyNAS @@ -540,6 +554,8 @@ HostConfig() { CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" LOGFILE="$DBDIR/DBRepair.log" LOG_TOOL="logger" + TMPDIR="$PKGDIR/temp" + SYSTMP="$TMPDIR" HaveStartStop=1 StartCommand="systemctl start fvapp-plexmediaserver" @@ -561,6 +577,8 @@ HostConfig() { CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" LOGFILE="$DBDIR/DBRepair.log" LOG_TOOL="logger" + TMPDIR="/tmp" + SYSTMP="$TMPDIR" HostType="ASUSTOR" return 0 @@ -577,6 +595,8 @@ HostConfig() { CACHEDIR="$HOME/Library/Caches/PlexMediaServer/PhotoTranscoder" LOGFILE="$DBDIR/DBRepair.log" LOG_TOOL="logger" + TMPDIR="/tmp" + SYSTMP="$TMPDIR" # MacOS uses pgrep and uses different stat options PIDOF="pgrep" @@ -608,7 +628,8 @@ HostConfig() { CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" LOGFILE="$DBDIR/DBRepair.log" LOG_TOOL="logger" - + TMPDIR="$(dirname $AppSuppDir)/plexmediaserver/tmp_transcoding" + SYSTMP="$TMPDIR" HostType="Western Digital" return 0 @@ -619,6 +640,9 @@ HostConfig() { elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] || [ "$(grep 0::/ /proc/1/cgroup)" = "0::/" ] || [ "$(grep libpod /proc/1/cgroup | wc -l)" -gt 0 ] || [ "$(grep kube /proc/1/cgroup | wc -l)" -gt 0 ]; then + TMPDIR="/tmp" + SYSTMP="/tmp" + # HOTIO Plex image structure is non-standard (contains symlink which breaks detection) if [ -n "$(grep -irslm 1 hotio /etc/s6-overlay/s6-rc.d)" ]; then PLEX_SQLITE=$(find /app/bin/usr/lib/plexmediaserver /app/usr/lib/plexmediaserver /usr/lib/plexmediaserver -maxdepth 0 -type d -print -quit 2>/dev/null); PLEX_SQLITE="$PLEX_SQLITE/Plex SQLite" @@ -628,6 +652,7 @@ HostConfig() { CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" LOGFILE="$DBDIR/DBRepair.log" LOG_TOOL="logger" + if [ -d "/run/service/plex" ] || [ -d "/run/service/service-plex" ]; then SERVICE_PATH=$([ -d "/run/service/plex" ] && echo "/run/service/plex" || [ -d "/run/service/service-plex" ] && echo "/run/service/service-plex") HaveStartStop=1 @@ -724,6 +749,8 @@ HostConfig() { CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" LOGFILE="$DBDIR/DBRepair.log" LOG_TOOL="logger" + TMPDIR="/tmp" + SYSTMP="/tmp" HostType="$(grep PRETTY_NAME /etc/os-release | sed -e 's/^.*="//' | tr -d \" )" HaveStartStop=1 @@ -1651,6 +1678,48 @@ DoPrunePhotoTranscoder() { } +DoPurgeTmp() +{ + # Purge files from the TMP and Transcoder_Temp directories + PurgeIt=0 + + # If scripted / command line options, clean automatically + if [ $Scripted -eq 1 ]; then + PurgeIt=1 + else + Output "Counting how many files are more than one day old." + FileCount=$(find "/tmp" -name pms-\* -mtime +1 -print | grep -v systemd | grep -v Easy | wc -l) + FileCount=$(( $FileCount + $(find "/tmp" \( -name \*.jpg -o -name \*.jpeg -o -name \*.png \) -mtime +1 | wc -l ))) + # If nothing found, continue back to the menu + [ $FileCount -eq 0 ] && Output "No files found to purge." && return + + # Ask if we should remove it + if ConfirmYesNo "OK to purge $FileCount files? "; then + PurgeIt=1 + fi + fi + + # Purge old the PMS files ? + if [ $PurgeIt -eq 1 ]; then + Output "Purging started." + WriteLog "Purge - START." + PurgeFiles="/tmp/PurgeList.$$" + find "$TMPDIR" /tmp -name pms-\* -mtime +1 -print | grep -v systemd | grep -v Easy -print > "$PurgeFiles" 2>> /dev/null + find "$TMPDIR" /tmp \( -name \*.jpg -o -name \*.jpeg -o -name \*.png \) -mtime +1 -print >> "$PurgeFiles" 2>> /dev/null + WriteLog "Purge - Removing $FileCount files." + while read Path + do + rm -rf "$Path" >> /dev/null 2>> /dev/null + done < "$PurgeFiles" + + rm -f "$PurgeFiles" + + Output "Purging completed." + WriteLog "Purge - PASS." + fi + +} + ############################################################# # Main utility begins here # ############################################################# @@ -1778,6 +1847,8 @@ fi # Set tmp dir so we don't use RAM when in DBDIR DBTMP="./dbtmp" mkdir -p "$DBDIR/$DBTMP" + +# Now set as DBTMP export TMPDIR="$DBTMP" export TMP="$DBTMP" @@ -1862,6 +1933,7 @@ do echo "" echo " 21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache." + echo " 22 - 'purge' - Purge (remove) all temporary files left by PMS & Transcoder in Temp Dir." [ $IgnoreErrors -eq 0 ] && echo " 42 - 'ignore' - Ignore duplicate/constraint errors." [ $IgnoreErrors -eq 1 ] && echo " 42 - 'honor' - Honor all database errors." @@ -2181,6 +2253,19 @@ do WriteLog "Prune - PASS" ;; + 22|purg*) + + # Check if PMS running + if IsRunning; then + WriteLog "Purge - FAIL - PMS runnning" + Output "Unable to purge temp files. PMS is running." + continue + fi + + WriteLog "Purge - START" + DoPurgeTmp + WriteLog "Purge - PASS" + ;; # Ignore/Honor errors 42|igno*|hono*) diff --git a/README.md b/README.md index 2c6986f..aded9c2 100644 --- a/README.md +++ b/README.md @@ -933,7 +933,9 @@ Select 11 - 'status' - Report status of PMS (run-state and databases). 12 - 'undo' - Undo last successful command. - 21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache. + 21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache older than specific age. + 22 - 'purge' - Purge (remove) all temporary files left by PMS & Transcoder in Temp Dir.' + 42 - 'ignore' - Ignore duplicate/constraint errors. 88 - 'update' - Check for updates. diff --git a/ReleaseNotes b/ReleaseNotes index 28dce18..c3c3efd 100644 --- a/ReleaseNotes +++ b/ReleaseNotes @@ -8,6 +8,11 @@ ![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg) # Release Info: +v1.09.00 + + 1. Purge command - Add 'purge' command to clean up all temporary transcoder and image files. + (usually found in /tmp) + v1.08.00 1. Linuxserver.io - Add support for new start/stop path.