#! /bin/bash
# /etc/init.d/dstore
 
### BEGIN INIT INFO
# Provides:          dstore
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO
 
path_to_start=/opt/dstore/bin/start.sh
path_to_stop=/opt/dstore/bin/stop.sh
node=`which node`
app_name=dstore
log_file=/var/log/$app_name.log
 
# Carry out specific functions when asked to by the system
case "$1" in
  start)
    echo "* starting $app_name * "
    echo "* starting $app_name * [`date`]" >> $log_file
    source /etc/dstore/dstore.conf
    export HOME=/etc/dstore
    exec $path_to_start >> $log_file 2>&1&
    ;;
  stop)
    echo "* stopping $app_name * "
    echo "* stopping $app_name * [`date`]" >> $log_file
    export HOME=/etc/dstore
    exec $path_to_stop > /dev/null
    ;;
  restart)
    echo "* restarting $app_name * "
    echo "* restarting $app_name * [`date`]" >> $log_file
    service dstore stop
    service dstore start
    ;;
  *)
    echo "Usage: /etc/init.d/dstore {start|stop|restart}"
    exit 1
    ;;
esac
 
exit 0
