DroboApps and Daemons

In my spare time I’ve been playing around with the Drobo file system and installing some DroboApps. Unlike my Netgear ReadyNAS and it’s packages, DroboApps are a little more primitive when it comes to installation. I guess that is a good thing as it allows for some customisation. But there is of course a learning curve that goes along with that. Just this week I helped my brother install and setup SABnzbd, CouchPotato and SickBeard on his Drobo box.

The installation of the DroboApps was relatively straightforward, and there is some good material out there that helps you to do just that. But one thing we noticed was the lack of information relating to how to get the apps running automatically upon system startup. So here I have included the scripts we used to get the daemons running after a system reboot.

Copy the contents to a file called service.sh in the DroboApps directory for each of the applications. To do this you should SSH into the Drobo, change into the directory of the app and open a ‘vi’ window and paste the contents into it. If you copy the contents to a file on Windows then you will have DOS carriage return characters in the scripts and this will cause issues when Drobo tries to run it. The way things work is that when the Drobo file system starts up it looks inside each of the DroboApps directory and looks for a file called service.sh. The file system then runs this script with the argument start, this is used to start the application. The way that the script works is that a center include set of subroutines are included in each service.sh script that wants you to provide a subroutine called start() that will start your application. That’s fairly straightforward, but the key thing is that when you start your application you need make sure a file is created that stores the Process ID of the running application. This important because this file, called the pidfile, and it’s contents is then used to stop the process upon system shutdown or when the application wants to be restarted.

Below is sample service scripts for SABnzbd, CouchPotato and SickBeard.

SABnzbd

#!/bin/sh
#
# SABnzbd daemon

. /etc/service.subr

prog_dir=`dirname \`realpath $0\``
piddir=${prog_dir}
cfgfile=/mnt/DroboFS/.sabnzbd/sabnzbd.ini
python=/mnt/DroboFS/Shares/DroboApps/python2/bin/python

name="SABnzbd"
version="1.0"

start()
{
  ${python} ${prog_dir}/SABnzbd.py --daemon --config-file ${cfgfile} --pid ${piddir}   
}

case "$1" in
  start)
    start_service
    ;;
  stop)
    stop_service
    ;;
  restart)
    stop_service
    sleep 3
    start_service
    ;;
  status)
    status
    ;;
  *)
    echo "Usage: $0 [start|stop|restart|status]"
    exit 1
    ;;
esac

CouchPotato

#!/bin/sh
#
# CouchPotato daemon

. /etc/service.subr

prog_dir=`dirname \`realpath $0\``
pidfile=${prog_dir}/couchpotato.pid
python=/mnt/DroboFS/Shares/DroboApps/python2/bin/python

name="CouchPotato"
version="1.0"

start()
{
  ${python} ${prog_dir}/CouchPotato.py -d --pidfile ${pidfile}    
}

case "$1" in
  start)
    start_service
    ;;
  stop)
    stop_service
    ;;
  restart)
    stop_service
    sleep 3
    start_service
    ;;
  status)
    status
    ;;
  *)
    echo "Usage: $0 [start|stop|restart|status]"
    exit 1
    ;;
esac

SickBeard

#!/bin/sh
#
# SickBeard daemon

. /etc/service.subr

prog_dir=`dirname \`realpath $0\``
pidfile=${prog_dir}/sickbeard.pid
python=/mnt/DroboFS/Shares/DroboApps/python2/bin/python

name="SickBeard"
version="1.0"

start()
{
  rm -f ${pidfile}
  ${python} ${prog_dir}/SickBeard.py --daemon --pidfile ${pidfile}
}

case "$1" in
  start)
    start_service
    ;;
  stop)
    stop_service
    ;;
  restart)
    stop_service
    sleep 3
    start_service
    ;;
  status)
    status
    ;;
  *)
    echo "Usage: $0 [start|stop|restart|status]"
    exit 1
    ;;
esac

UPDATE: After some testing, I found that SickBeard wasn’t starting after a reboot of the Drobo. Apparently the PID file was not being deleted on shutdown, so I updated the service script to remove the pidfile when start is called.