#!/bin/sh
### BEGIN INIT INFO
# Provides:          application
# Required-Start:    
# Required-Stop:     
# Should-Start:	     
# Should-Stop:       
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Vendor application
# Description:       This is the primary appliance application 
### END INIT INFO


PATH=/sbin:/bin:/usr/sbin:/usr/bin
DESC="Vendor Application"
NAME="application"
EXECUTABLE="/usr/sbin/$NAME"
SCRIPTNAME=/etc/init.d/$NAME

# Gracefully exit if the package has been removed.
test -x $EXECUTABLE || exit 0


# int log_begin_message (char *message)
log_begin_msg () {
    if [ -z "$1" ]; then
    return 1
    fi
    echo " * $@"
}

# int log_end_message (char *message)
log_end_msg () {
    if [ -z "$1" ]; then
    return 1
    fi
    echo " * $@"
}

#
#       Function that starts the application.
#
d_start() {
    $EXECUTABLE &
}

#
#       Function that stops the application.
#
d_stop() {
    pkill $EXECUTABLE
}

#
#       Function that reload the config file for the daemon/service.
#
d_reload() {
    pkill $EXECUTABLE
    $EXECUTABLE && return 0
}

#
#       Function that check the status of the daemon/service.
#
d_status() {
    status=$?
    if [ $status = 0 ]; then
        echo "$DESC is running"
        return 0
    else
        echo "$DESC is not running"
        return 3
    fi
}

case "$1" in
    start)
        log_begin_msg "Starting $DESC: $NAME"
        d_start
        ;;
    stop)
        log_begin_msg "Stopping $DESC: $NAME"
        d_stop
        ;;
    reload)
        log_begin_msg "Reloading services for $DESC: $NAME"
        d_reload
        ;;
    restart|force-reload)
        log_begin_msg "Restarting $DESC: $NAME"
        d_reload
        ;;
    status)
        d_status
	;;
    *)
        echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|reload|status}" >&2
        exit 1
        ;;
esac

exit $?
