
#!/bin/sh

# Add specific tools for COMPONENT
export LD_LIBRARY_PATH=/usr/lib/datastatistics/formatter:/usr/lib/datastatistics/report:/usr/lib/datastatistics/libs:/usr/lib/datastatistics/addons

PID="/var/run/datastatistics.pid"




start() {
    if [ ! -e /cfg/system/datastatistics ]; then
        echo "Creation of folder"
        mkdir -p /cfg/system/datastatistics
    fi
    if [ -e "${PID}" ]; then
        echo "datastatistics already started"
    else
        echo "starting datastatistics ..."
        glib-app -n datastatistics
    fi
}

stop() {
    if [ -e "${PID}" ]; then
        echo "stopping datastatistics ..."
        killall datastatistics
    else
        echo "datastatistics not running"
    fi
}



case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;

    restart)
        stop
        start
        ;;
    debuginfo)
        if [ -f "${PID}" ]; then
            echo "datastatistics is running, pid=$(cat ${PID})"
        else
            echo "datastatistics is not running"
        fi
        ;;
    *)
        echo "Usage : $0 [start|stop|restart|debuginfo]"
        ;;
esac
