Add Prune

Delete all images and temporary transcoder files/dirs in "/tmp".
This commit is contained in:
ChuckPa
2024-11-06 20:59:00 -05:00
parent f11d8de6be
commit c39e70b430
3 changed files with 99 additions and 7 deletions

View File

@@ -2,12 +2,12 @@
######################################################################### #########################################################################
# Plex Media Server database check and repair utility script. # # Plex Media Server database check and repair utility script. #
# Maintainer: ChuckPa # # Maintainer: ChuckPa #
# Version: v1.08.00 # # Version: v1.09.00 #
# Date: 28-Aug-2024 # # Date: 06-Nov-2024 #
######################################################################### #########################################################################
# Version for display purposes # Version for display purposes
Version="v1.08.00" Version="v1.09.00"
# Have the databases passed integrity checks # Have the databases passed integrity checks
CheckedDB=0 CheckedDB=0
@@ -29,6 +29,10 @@ RemoveDuplicates=0
# Keep track of how many times the user's hit enter with no command (implied EOF) # Keep track of how many times the user's hit enter with no command (implied EOF)
NullCommands=0 NullCommands=0
# Default TMP dir for most hosts
TMPDIR="/tmp"
SYSTMP="/tmp"
# Global variable - main database # Global variable - main database
CPPL=com.plexapp.plugins.library CPPL=com.plexapp.plugins.library
@@ -220,8 +224,8 @@ FreeSpaceAvailable() {
SpaceNeeded=$((LibSize + BlobsSize)) SpaceNeeded=$((LibSize + BlobsSize))
# Compute need (minimum $Multiplier existing; current, backup, temp and room to write new) # Compute need (minimum $Multiplier existing; current, backup, temp and room to write new)
SpaceNeeded="$(expr $SpaceNeeded '*' $Multiplier)" SpaceNeeded=$((SpaceNeeded '*' $Multiplier))
SpaceNeeded="$(expr $SpaceNeeded / 1000000)" SpaceNeeded=$((SpaceNeeded / 1000000))
# If need < available, all good # If need < available, all good
[ $SpaceNeeded -lt $SpaceAvailable ] && return 0 [ $SpaceNeeded -lt $SpaceAvailable ] && return 0
@@ -396,6 +400,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
TMPDIR="$AppSuppDir/Plex Media Server/tmp"
SYSTMP="$TMPDIR"
# We are done # We are done
HostType="Synology (DSM 7)" HostType="Synology (DSM 7)"
@@ -426,6 +432,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
TMPDIR="$AppSuppDir/Plex Media Server/tmp"
SYSTMP="$TMPDIR"
HostType="Synology (DSM 6)" HostType="Synology (DSM 6)"
@@ -451,6 +459,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid" PID_FILE="$AppSuppDir/Plex Media Server/plexmediaserver.pid"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
TMPDIR="$AppSuppDir/tmp"
SYSTMP="$TMPDIR"
# Start/Stop # Start/Stop
if [ -e /etc/init.d/plex.sh ]; then if [ -e /etc/init.d/plex.sh ]; then
@@ -476,6 +486,8 @@ HostConfig() {
DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases" DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger" LOG_TOOL="logger"
TMPDIR="/var/snap/plexmediaserver/common/tmp"
SYSTMP="$TMPDIR"
HaveStartStop=1 HaveStartStop=1
StartCommand="snap start plexmediaserver" StartCommand="snap start plexmediaserver"
@@ -522,6 +534,8 @@ HostConfig() {
HaveStartStop=1 HaveStartStop=1
StartCommand="systemctl start plexmediaserver" StartCommand="systemctl start plexmediaserver"
StopCommand="systemctl stop plexmediaserver" StopCommand="systemctl stop plexmediaserver"
TMPDIR="/tmp"
SYSTMP="$TMPDIR"
return 0 return 0
# Netgear ReadyNAS # Netgear ReadyNAS
@@ -540,6 +554,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger" LOG_TOOL="logger"
TMPDIR="$PKGDIR/temp"
SYSTMP="$TMPDIR"
HaveStartStop=1 HaveStartStop=1
StartCommand="systemctl start fvapp-plexmediaserver" StartCommand="systemctl start fvapp-plexmediaserver"
@@ -561,6 +577,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger" LOG_TOOL="logger"
TMPDIR="/tmp"
SYSTMP="$TMPDIR"
HostType="ASUSTOR" HostType="ASUSTOR"
return 0 return 0
@@ -577,6 +595,8 @@ HostConfig() {
CACHEDIR="$HOME/Library/Caches/PlexMediaServer/PhotoTranscoder" CACHEDIR="$HOME/Library/Caches/PlexMediaServer/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger" LOG_TOOL="logger"
TMPDIR="/tmp"
SYSTMP="$TMPDIR"
# MacOS uses pgrep and uses different stat options # MacOS uses pgrep and uses different stat options
PIDOF="pgrep" PIDOF="pgrep"
@@ -608,7 +628,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger" LOG_TOOL="logger"
TMPDIR="$(dirname $AppSuppDir)/plexmediaserver/tmp_transcoding"
SYSTMP="$TMPDIR"
HostType="Western Digital" HostType="Western Digital"
return 0 return 0
@@ -619,6 +640,9 @@ HostConfig() {
elif [ "$(grep docker /proc/1/cgroup | wc -l)" -gt 0 ] || [ "$(grep 0::/ /proc/1/cgroup)" = "0::/" ] || 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 [ "$(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) # 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 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" 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" CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger" LOG_TOOL="logger"
if [ -d "/run/service/plex" ] || [ -d "/run/service/service-plex" ]; then 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") SERVICE_PATH=$([ -d "/run/service/plex" ] && echo "/run/service/plex" || [ -d "/run/service/service-plex" ] && echo "/run/service/service-plex")
HaveStartStop=1 HaveStartStop=1
@@ -724,6 +749,8 @@ HostConfig() {
CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder" CACHEDIR="$AppSuppDir/Plex Media Server/Cache/PhotoTranscoder"
LOGFILE="$DBDIR/DBRepair.log" LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger" LOG_TOOL="logger"
TMPDIR="/tmp"
SYSTMP="/tmp"
HostType="$(grep PRETTY_NAME /etc/os-release | sed -e 's/^.*="//' | tr -d \" )" HostType="$(grep PRETTY_NAME /etc/os-release | sed -e 's/^.*="//' | tr -d \" )"
HaveStartStop=1 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 # # Main utility begins here #
############################################################# #############################################################
@@ -1778,6 +1847,8 @@ fi
# Set tmp dir so we don't use RAM when in DBDIR # Set tmp dir so we don't use RAM when in DBDIR
DBTMP="./dbtmp" DBTMP="./dbtmp"
mkdir -p "$DBDIR/$DBTMP" mkdir -p "$DBDIR/$DBTMP"
# Now set as DBTMP
export TMPDIR="$DBTMP" export TMPDIR="$DBTMP"
export TMP="$DBTMP" export TMP="$DBTMP"
@@ -1862,6 +1933,7 @@ do
echo "" echo ""
echo " 21 - 'prune' - Prune (remove) old image files (jpeg,jpg,png) from PhotoTranscoder cache." 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 0 ] && echo " 42 - 'ignore' - Ignore duplicate/constraint errors."
[ $IgnoreErrors -eq 1 ] && echo " 42 - 'honor' - Honor all database errors." [ $IgnoreErrors -eq 1 ] && echo " 42 - 'honor' - Honor all database errors."
@@ -2181,6 +2253,19 @@ do
WriteLog "Prune - PASS" 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 # Ignore/Honor errors
42|igno*|hono*) 42|igno*|hono*)

View File

@@ -933,7 +933,9 @@ Select
11 - 'status' - Report status of PMS (run-state and databases). 11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command. 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. 42 - 'ignore' - Ignore duplicate/constraint errors.
88 - 'update' - Check for updates. 88 - 'update' - Check for updates.

View File

@@ -8,6 +8,11 @@
![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg) ![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg)
# Release Info: # 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 v1.08.00
1. Linuxserver.io - Add support for new start/stop path. 1. Linuxserver.io - Add support for new start/stop path.