#!/bin/sh
#
# Copyright 2003 Meru Networks
# All rights reserved.
#
PROC=/opt/meru/bin/convert2cef
START_DELAY=.2

MNAME=`basename $PROC`
PIDFILE=/var/run/${MNAME}.pid
LOG=/opt/wlan/var/log/${MNAME}.log

CONF_FILE=/opt/wlan/var/run/running-db/ceflog.conf

if [ -f /etc/init.d/meru-functions ]; then
    . /etc/init.d/meru-functions
else
    echo "/etc/init.d/meru-functions must exist to use $0"; exit 1
fi

[ -f $CONF_FILE ] || echo "disable" > $CONF_FILE
start() {

	# Start CEFLOG
	if [ -f $CONF_FILE ]; then

		vrfy_combo `cat $PIDFILE 2>/dev/null` && {
			return
		}

		echo "============ $0 start =================" >> $LOG
		cd /opt/wlan/etc

		$PROC >> $LOG 2>&1 &
		sleep $START_DELAY
		write_pid
		vrfy `cat $PIDFILE 2>/dev/null` || warning "$PROC did not start. Will try again."
	fi
}

stop() {

	monit_stop_process
}

case "$1" in
        start)
                if vrfy monit; then
                        start_with_monit $MNAME
                else
                        start
                fi
                ;;
        stop)
                if vrfy monit; then
                        stop_with_monit $MNAME
                else
                        stop
                fi
                ;;
        restart)
                if vrfy monit; then
                        restart_with_monit $MNAME
                else
                        stop
                        start
                fi
                ;;
        mstart)
                start
                ;;
        mstop)
                stop
                ;;
        *)
                echo $"Usage: $prog {start|stop|restart}"
                exit 1
esac

exit 0
