#!/bin/sh
### BEGIN INIT INFO
# Provides:          kickidlergrabber
# Required-Start:    $remote_fs $network $named $all
# Required-Stop:     $remote_fs $network $named $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     false
# Short-Description: TeleLinkSoft helper
# Description:       A telemetry collector.
### END INIT INFO

# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="TeleLinkSoft helper"
NAME="grabber"
DAEMON="/opt/TeleLinkSoftHelper/bin/$NAME"

# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0

# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.2-14) to ensure that this file is present
# and status_of_proc is working.
. /lib/lsb/init-functions

is_running()
{
    if "$DAEMON" -v | grep "not running" >/devnull 2>/dev/null;
    then
        return 0
    else
        return 1
    fi
}

case "$1" in
    start)
        [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
        "$DAEMON" >/dev/null 2>/dev/null
        case "$?" in
            0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
            *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
    ;;

    stop)
        [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
        "$DAEMON" -t >/dev/null 2>/dev/null
        case "$?" in
            0) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
            *) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
        esac
    ;;

    status)
        is_running
        if [ "$?" = "1" ];
        then
            log_success_msg "$NAME is running"
        else
            log_failure_msg "$NAME is not running"
        fi
    ;;

    restart|force-reload)
        log_daemon_msg "Restarting $DESC" "$NAME"
        "$DAEMON" -restart >/dev/null 2>/dev/null
        case "$?" in
            0) log_end_msg 0 ;;
            *) log_end_msg 1 ;;
        esac
    ;;

    *)
        echo "Usage: $0 {start|stop|status|restart|force-reload}" >&2
        exit 3
esac
exit 0
