Page 1 of 1

Power down best practice

Posted: October 10th, 2011, 2:54 am
by Baz8755
The NAS box I am running SABnzbd on is set to power on and off every day, this has lead me to wonder what I should be doing to prevent any issues with SABnzbd.

I notice it has scheduling for pause and shutdown and was wondering whether to set a schedule to pause/shutdown just before the NAS box closes down. Also what would then happen when SABnzbd is restarted, will it resume any paused activity of will I have to put a schedule in for that too.

Cheers

Baz

Re: Power down best practice

Posted: October 10th, 2011, 3:14 am
by shypike
Forceful shutdown is always a bad idea.
If your OS cannot shutdown SABnzbd properly, then the safest is to schedule a pause.
Give it at least 5 minutes to dump its article cache to disk to be on the safe side.
You should schedule a resume event too.
The reason is that at startup the schedules are evaluated to determine what the state would have been.

Re: Power down best practice

Posted: October 10th, 2011, 7:19 am
by Baz8755
So on my linkstation I suppose I could put the following line in rcS

sleep 30
/usr/bin/wget -q --delete-after "http://127.0.0.1:8080/sabnzbd/api?mode=resume"


and the following lines in the shutdown script (wherever that may be, sure I'll find it tonight)

/usr/bin/wget -q --delete-after "http://127.0.0.1:8080/sabnzbd/api?mode=pause"
sleep 300
/usr/bin/wget -q --delete-after "http://127.0.0.1:8080/sabnzbd/api?mode=shutdown"
sleep 30

Re: Power down best practice

Posted: October 10th, 2011, 11:52 am
by shypike
Yes, provided that you append &apikey=blabla
And assuming you used 0.0.0.0 as host address.
If not, you'll need to use the local IP address (like 192.168.1.xxx).

Re: Power down best practice

Posted: October 10th, 2011, 3:17 pm
by Baz8755
Sorted, pretty much as discussed.

Didn't need to send a resume on startup in rcS as it seems to start in a running state.
Placed shutdown commands in rcDown, this gave me a little trouble as linkstation seems to like replacing on every boot and I couldn't work out where. So I just recopied it back at the end of rcS.

Re: Power down best practice

Posted: October 15th, 2011, 9:46 am
by Baz8755
In case anyone else is interested here is my startup/shutdown script for Buffalo Linkstation.

You will need to reference it in rcS, rcDown,standyby,rcDown and will then need to take a copy of rcDown as SABnzbd.rcDown as this seems to get overwritten.

Upon shutdown the script will set SABnzbd into pause mode, wait up to 10 minutes for any unpacks to finish and then wait up to 10 minutes for SABnzbd to cleanly close down.

Enjoy.

#!/bin/sh
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/opt/bin
#
#Script to start/stop SABnzbd
#

Send_wait_pause()
{
#Send pause command
/usr/bin/wget -q -O - "http://192.168.0.21:8080/sabnzbd/api?mo ... ikey=<your key>"
LoopCount=0
ClearCount=0
#Wait for RARs & PARs to close
while [ $LoopCount -lt $2 -a $ClearCount -lt $1 ]
do
ProcessCount=$(ps | grep -v grep | grep -e unrar -e par2 -e unzip | wc -l)
if [ $ProcessCount -eq 0 ]
then
ClearCount=`expr $ClearCount + 1`
else
ClearCount=0
fi
LoopCount=`expr $LoopCount + 1`
sleep 30
done
}

Send_wait_close()
{
#Send close command
/usr/bin/wget -q -O - "http://192.168.0.21:8080/sabnzbd/api?mo ... ikey=<your key>""
LoopCount=0
ClearCount=0
#Wait for RARs & PARs & SABnzbd to close
while [ $LoopCount -lt $2 -a $ClearCount -lt $1 ]
do
ProcessCount=$(ps | grep -v grep | grep -e unrar -e par2 -e unzip -e SABnzbd.py | wc -l)
if [ $ProcessCount -eq 0 ]
then
ClearCount=`expr $ClearCount + 1`
else
ClearCount=0
fi
LoopCount=`expr $LoopCount + 1`
sleep 30
done
}

Startup()
{
python2.5 /opt/share/SABnzbd/SABnzbd.py -f /opt/share/SABnzbd/SABnzbd.ini -d -s 0.0.0.0
cp /etc/init.d/SABnzbd.rcDown /etc/init.d/rcDown
}


case $1 in
start)
Startup
;;
resume)
Startup
;;
standby)
Send_wait_pause 4 20
Send_wait_close 1 20
;;
stop)
Send_wait_pause 4 20
Send_wait_close 1 20
;;
*)
;;
esac