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