#!/bin/sh
### BEGIN INIT INFO
# Provides:          MicroBrowserSbc
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: SpiderControl MicroBrowserSbc
# Description:       SpiderControl MicroBrowserSbc (/etc/init.d/microbrowser)
### END INIT INFO

#-- This script allows to start/stop/restart an application
#-- Set env. variable
#
APPLIC=MicroBrowserSbc
APPLIC_HOME_DIR=$HOME/MicroBrowserSbc/

#LOG=/dev/nul
LOG=/var/log/$APPLIC.cmd

#LOG_FILE=/dev/nul
LOG_FILE=/var/log/$APPLIC.log

# PATH=/bin:/usr/bin:/usr/local/bin:/usr/local/sbin
# export PATH

#. /lib/init/vars.sh
#. /lib/lsb/init-functions

echo `date` `tty` $0 $* >>$LOG
echo `date` `tty` $0 $* >>$LOG_FILE

cd $APPLIC_HOME_DIR

case "$1" in
  start)
    # log_begin_msg "Start $APPLIC..."
    echo "-- Start $APPLIC..."
    ./$APPLIC > $LOG_FILE 2>&1 &
    echo "* $APPLIC started!"
    # log_end_msg 0
    ;;
  stop)
    echo "-- Stop $APPLIC..."
    # pkill -f "$APPLIC"
    pkill -f $APPLIC >> $LOG_FILE 2>&1
    echo "* $APPLIC stopped!"
    ;;
  restart|reload|force-reload)
    echo "-- Restart $APPLIC..."
    echo "* Stop..."
    pkill -f $APPLIC >> $LOG_FILE 2>&1
    echo "* $APPLIC stopped!"
    echo "* Start..."
    ./$APPLIC >> $LOG_FILE 2>&1 &
    echo "* $APPLIC started!"
    echo "Done."
    ;;
  help)
    echo "Usage: $0 {start|stop|restart}"
    exit 1
    ;;
esac

exit 0

