Skip to main content

XBMC memory leak remedy

· One min read

XBMC (now Kodi) has always had a tendency of leaking memory, so that it will eventually thrash and crash. My simple solution to this is to run xbmc inside a for loop instead of directly (just run the script from .xinitrc):

xbmc_angel.sh:

#!/bin/bash
while [ 1 ]; do
xbmc
nohup sleep 10
done

...And add the following to the local XBMC user's crontab:

0 4 * * *       killall xbmc.bin

This will kill XBMC every night at 4 o'clock. And give you a fresh XBMC every day!

How to download videos from Pepper Flash on linux

· One min read

The new Pepper Flash plugin broke my old script for listing/downloading cached flash/flv videos.

Here is a new script. Uses sudo because the /proc/$PID/fd directory is root only. This solution is based on silviot's solution here: http://superuser.com/questions/622606/how-do-i-save-the-buffered-flash-video-on-linux.

#!/bin/bash
for FLASHPID in $( pgrep -f chrom ) ; do (for FLASHFILE in $(sudo ls -l /proc/$FLASHPID/fd|egrep "(/tmp/Flash|Pepper Data)" | sed -r 's/^.* ([0-9]+) -> .*$/\1/'); do echo /proc/$FLASHPID/fd/$FLASHFILE; done ); done

Then you can just copy the file into home, like:

cp /proc/26493/fd/30 ~/

ReadyNAS RN102 constant activity remedy

· One min read

My Netgear ReadyNAS RN102 keeps constantly writing to a file /var/readynasd I don't want to hold my breath waiting for Netgear to fix this so I took matters into my own hands and implemented a TMPFS fix for my NAS. What it does is mount /var/readynasd as a tmpfs of 2MB, and copy files to here from /etc/readynas-db on every boot, and copy back every hour, and on shutdown.

Setup instructions​

systemctl stop readynasd
mkdir /etc/readynasd-db
cp -a /var/readynasd /etc/readynasd-db/

Edit /lib/systemd/system/tmpdb.service:

[Unit]
Description=Mount RAMFS for SQLITE DB file
Before=readynasd.service

[Service]
Type=oneshot
ExecStart=/bin/sh -c "mount -t tmpfs -o size=2m tmpfs /var/readynasd && cp -a /etc/readynasd-db/readynasd /var/"
#ExecStop=/bin/sh -c "cp -a /var/readynasd /etc/readynasd-db/" # TODO not working
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Edit /etc/cron.daily/tmpdb-sync

#!/bin/bash
cp -a /var/readynasd /etc/readynasd-db/

Now finish up:

chmod +x /etc/cron.daily/tmpdb-sync
systemctl enable tmpdb
reboot

ReadyNAS startup/boot script

· One min read

I needed to add some startup command to run as root on my Netgear ReadyNAS (RN102). Turns out you don't have any /etc/rc.local, so I added a new boot script /etc/init.d/local:

#! /bin/sh
### BEGIN INIT INFO
# Provides: local
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Local scripts
# Description: Local scripts
### END INIT INFO

PATH=/sbin:/bin
. /lib/init/vars.sh

do_start () {
hdparm -S 253 /dev/sdc
}

case "$1" in
start)
do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
# No-op
;;
status)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac

:

Just type whatever u need inside do_start. I needed to set a higher spindown timeout.

Then:

chmod +x /etc/init.d/local
update-rc.d local defaults

Tested on ReadyNASOS 6.1.6