Showing posts with label DroboFS. Show all posts
Showing posts with label DroboFS. Show all posts

Sunday, June 20, 2010

Activate the cron daemon on a DroboFS

I recently purchased a DroboFS NAS from DataRobotics. The device runs a minimal Marvell Linux OS on top of a low power ARM CPU (ARM926EJ-S).

The DroboFS supports third party development through the DroboApps platform. This allows end users to compile ARM applications using the GNU tool chain and run them on their DroboFS. On top of this these applications can be run as services using a small service API provided by DroboApps.

A number of DroboApps are available to enable dormant services on the DroboFS including the SSH, HTTP and FTP servers.

The DroboFS ships with a cron daemon tucked away at /usr/sbin/crond however there is no DroboApp available to enable the daemon. To rectify this I have written a small DroboApp script to activate the cron daemon at boot.

To get cron running as a service you'll need to do the following:
  1. Enable DroboApps on your DroboFS.
  2. Install the Dropbear SSH DroboApp.
  3. SSH into your DroboFS
  4. Create a directory for the cron DroboApp:
    mkdir /mnt/DroboFS/Shares/DroboApps/crond
  5. Save the following service.sh into your cron DroboApp directory
    #!/bin/sh
    # ------------------------------------------------------------
    # service.sh for cron DroboApp
    #
    # Exposes the crond binary existing on the DroboFS as a 
    # DroboApps service.
    # ------------------------------------------------------------
    
    # Binaries used
    AWK="/usr/bin/awk"
    GREP="/bin/grep"
    CROND="/usr/sbin/crond"
    DATE="/bin/date +%Y:%m:%d-%H:%M:%S" # Nicely formatted date
    ECHO="/bin/echo"
    PS="/bin/ps"
    
    # Load the DroboApps service functions
    . /etc/service.subr
    
    # Required DroboApps variables
    prog_dir=`dirname \`realpath $0\``
    name="crond"                    # service name
    version="1.14.2"                # program version
    pidfile=${prog_dir}/crond.pid # location of pid file
    logfile=${prog_dir}/crond.log # location of log file
    
    # Start crond
    start()
    {
      # Start the service
      $CROND
    
      # Create the pidfile
      pid=`$PS | $GREP $CROND | $GREP -v grep | $AWK '{print $1}'`
      $ECHO $pid > $pidfile
    }
    
    case "$1" in
      start)
        start_service
        $ECHO "`$DATE` Started cron service" >> $logfile    
        ;;
      stop)
        stop_service
        $ECHO "`$DATE` Stopped cron service" >> $logfile    
        ;;
      restart)
        stop_service
        sleep 3
        start_service
        $ECHO "`$DATE` Restarted cron service" >> $logfile    
        ;;
      status)
        status
        ;;
      *)
        $ECHO "Usage: $0 [start|stop|restart|status]"
        exit 1
        ;;
    esac
    
  6. Restart your DroboFS.
Now the cron daemon is running from boot on your DroboFS. To add tasks for the cron daemon to run you will need to SSH into your DroboFS and run the following:
mkdir -p /var/spool/cron/crontabs
crontab -e
I hope someone finds this helpful.


2010-06-24: Edit added "mkdir -p /var/spool/cron/crontabs" Thanks pimvanderzwet