I found that Plex processes were accessing my drive every 30 minutes just to update the main log saying it was running but doing nothing. I decided to try to copy the method used by the Flash Memory Plugin which uses folder2ram. I initially tried adding the Plex log directory to its config file and then executing a folder2ram -generate.
It did generate the file, however, Plex has an extremely long path and it also contains a lot of spaces in the path which caused folder2ram to not execute correctly. I ended up having to manually remove the mutant named files that were mangled because of the spaces. This was just as well because adding it to folder2ram's config file would have lasted only until the next time the plug-in was updated. At that time any changes I had made would have been blown away by the update.
Besides the spaces in the path, the only other gotcha to doing this is the size of the log directory. Plex seems fairly bad at keeping the size of its log files reasonable. In 3 to 4 days I had been using Plex it had managed to generate 24 MB worth of logs. The DNLA log in particular seems to be able to grow without constraint. My earlier attempts failed because the initial 16 MB size of the tmpfs drive wasn't large enough. Eventually I increased the size to 128 MB and I added in a log cleanup routine to delete the older logs (ie "*.log.[3-9]"). Additionally I added a daily cron job to sync the data back to the disk.
Overview of what you need to do to implement:
Place file: /etc/init.d/plex_omv_tmpfs
chmod a+x /etc/init.d/plex_omv_tmpfs
insserv plex_omv_tmpfs
Place file: /etc/cron.daily/plex_omv_tmpfs_sync
chmod a+x /etc/cron.daily/plex_omv_tmpfs_sync
plex_omv_tmpfs
#! /bin/sh
### BEGIN INIT INFO
# Provides: plex_omv_tmpfs
# X-Start-Before: $syslog
# X-Stop-After: $syslog
# X-Interactive: yes
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Keeps Plex log files in RAM
# Description: Moves the contents of Plex log folder to RAM during boot
# and keeps it there until shutdown/reboot, when it
# copies the contents back to permanent storage.
### END INIT INFO
NAME=plex_omv_tmpfs
DIR="/media/e5f80c22-2bd8-427b-88f5-cad32e84e464/plexmediaserver/Library/Application Support/Plex Media Server/Logs"
DIRTRUE="/var/${NAME}/Logs"
LOCKFILE="/run/lock/${NAME}.lock"
do_start()
{
# Return
# 0 if transient log has been started
# 1 if transient log was already running
# 2 if transient log could not be started
[ -f "$LOCKFILE" ] && return 1
[ `id -u` -eq 0 ] || return 2
[ -d "$DIR" ] || return 2
# unmounting it if it was a tmpfs already
umount -l -t tmpfs "$DIR" 2> /dev/null
[ -d "$DIRTRUE" ] || mkdir -p "$DIRTRUE" || return 2
mount --bind "$DIR" "$DIRTRUE"
mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=128M $NAME "$DIR"
if [ $? -eq 0 ]; then
if cp -rfp "$DIRTRUE" -T "$DIR"; then
touch "$LOCKFILE"
return 0
fi
# Rollback the mount
umount -l "$DIR"
fi
# Rollback the directory mangling
umount -l "$DIRTRUE"
return 2
}
do_stop() {
# Return
# 0 if transient log has been stopped
# 1 if transient log was already stopped
# 2 if transient log could not be stopped
# other if a failure occurred
[ -f "$LOCKFILE" ] || return 1
# Check if I am root
[ `id -u` -eq 0 ] || return 2
# Merge back to permanent storage
cp -rfup "$DIR" -T "$DIRTRUE"
umount -l "$DIR"
umount -l "$DIRTRUE"
rm -r "$LOCKFILE"
return 0
}
do_reload() {
# Return
# 0 if transient log has been reloaded
# 1 if transient log was not running
# 2 if transient log could not be reloaded
[ -f "$LOCKFILE" ] || return 1
# Check if I am root
[ `id -u` -eq 0 ] || return 2
# Cleanup Old Logs (Optional)
find "$DIR" -type f -name "*.log.[3-9]" -exec rm -f {} \;
find "$DIRTRUE" -type f -name "*.log.[3-9]" -exec rm -f {} \;
# Merge back to permanent storage
cp -rfup "$DIR" -T "$DIRTRUE"
touch "$LOCKFILE"
return 0
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
status)
if [ -f "$LOCKFILE" ]; then
echo "$NAME is running"
else
echo "$NAME is stopped"
exit 1
fi
;;
reload)
do_reload
;;
*)
echo "Usage: $0 {start|stop|status|reload}" >&2
exit 3
;;
esac
exit
Alles anzeigen
plex_omv_tmpfs_sync
#!/bin/sh
#
# Synchronize RAM log directories daily.
#
set -e
NAME=plex_omv_tmpfs
[ -x /etc/init.d/${NAME} ] || exit 0
[ -f /run/lock/${NAME}.lock ] || exit 0
/etc/init.d/${NAME} reload
Alles anzeigen
Acknowledge/Sources:
- folder2ram (Good implementation on OMV)
- https://www.debian-administrat…/661/A_transient_/var/log (I learned a lot from this explanation)