#!/bin/bash

set -e
cd /dSolard

#. /lib/lsb/init-functions

case "$1" in
  start)
    printf "Start dSolard: "
    start-stop-daemon -S -u root -b -m -p /dSolard/dsolard.pid  -x /dSolard/dSolard
    [ $? = 0 ] && echo "OK" || echo "FAIL"
    ;;
  stop)
    printf "Stopping dSolard: "
    start-stop-daemon -K -s 3 -p /dSolard/dsolard.pid
    [ $? = 0 ] && echo "OK" || echo "FAIL"
    ;;
  configure)
    printf "Configure dSolard: "
    start-stop-daemon -S -u root -b -m -p /dSolard/dsolard.pid  -x /dSolard/dSolard configure
    [ $? = 0 ] && echo "OK" || echo "FAIL"
    ;;
  truncatetotime)
    printf "Reindex dSolard: "
    /dSolard/dSolard truncatetotime
    [ $? = 0 ] && echo "OK" || echo "FAIL"
    ;;
  *)
    echo "Usage: /etc/init.d/dsolard {start|stop}"
    exit 1
esac

exit 0



