#! /bin/sh
# /etc/init.d/domotix

### BEGIN INIT INFO
# Provides:          domotix
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO

# Carry out specific functions when asked to by the system
case "$1" in
   start)
    echo "Starting sb-admin.js"
    # run application you want to start
    #node /home/pi/domotix/sb-admin.js >> /home/pi/domotix.log
    cd /home/pi/domotix/
    sudo node sb-admin.js >> /home/pi/domotix/domotix.log &
   ;;
   stop)
    echo "Stopping sb-admin.js"
    # kill application you want to stop
    killall -9 node
    # Not a great approach for running
    # multiple node instances
    ;;
  *)
    echo "Usage: /etc/init.d/domotix {start|stop}"
    exit 1
    ;;
esac

exit 0
