#!/bin/bash

### BEGIN INIT INFO
# Provides:          eltex-radius-exporter
# Required-Start:    $network $syslog $remote_fs
# Required-Stop:     $network $syslog $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Eltex.Radius-exporter
# Description:       Eltex.Radius-exporter, part of Eltex.SoftWLC
### END INIT INFO

NAME=eltex-radius-exporter

# defaults

if [ -f /etc/default/$NAME ]; then
    source /etc/default/$NAME || exit 1
fi

BINARY="/usr/lib/$NAME/freeradius_exporter.bin"

start() {
    $BINARY --config=/etc/$NAME/config.json
}

stop() {
    killall ${NAME}
}

# Check the status of the process.
status() {
    if [ -e ${PIDFILE} ]; then
        status_of_proc -p ${PIDFILE} "$NAME process" && exit 0 || exit $?
    else
        log_daemon_msg "$NAME process is not running"
        log_end_msg 0
    fi
}

case $1 in
    start)
        start
    ;;
    stop)
        stop
    ;;
    restart|force-reload)
        stop
        start
    ;;
    status)
        status
    ;;
    *)
        # For invalid arguments, print the usage message.
        echo "Usage: $0 {start|stop|restart|force-reload|status}"
        exit 2
    ;;
esac
