#!/bin/sh

. /etc/PG.conf

RAMDISK="/usr/ramdisk"
FLOWEYE="${RAMDISK}/bin/floweye"

sys_warring="${RAMDISK}/bin/netev_alarm.sh"


warring_action()
{
    for pid in `ps -ax | grep "/netev_alarm.sh" | grep -v grep | awk '{print $1}'`;
    do
        kill -9 ${pid} >/dev/null 2>&1
    done

    notify2user=`${FLOWEYE} nev stat | grep "notify2user=" | cut -d"=" -f2`

    if [ "${1}" = "start" -a "${notify2user}" = "1" ]; then
        ${sys_warring} &
    fi
}


confsync_action()
{
    SYNC_CONF="${PGETC}/web/config_sync.conf"
    IPE_SYNCD="${RAMDISK}/bin/ipe_syncd"

    for pid in `ps -ax | grep "ipe_syncd" | grep -v grep | awk '{print $1}'`;
    do
        kill -9 ${pid} >/dev/null 2>&1
    done

    [ -f ${SYNC_CONF} ] && . ${SYNC_CONF}

    if [ "${1}" = "start" -a "${enable}" = "1" ]; then
        ${IPE_SYNCD} ${type}
    fi
}


# APP API
app_start()
{
    case "${1}" in
        "warring")
            warring_action "start"
            ;;

        "confsync_action")
            confsync_action "start"
            ;;

        *)
            warring_action "start"
            confsync_action "start"
            ;;
    esac
}


app_stop()
{
    case "${1}" in
        "warring")
            warring_action "stop"
            ;;

        "confsync_action")
            confsync_action "stop"
            ;;

        *)
            warring_action "stop"
            confsync_action "stop"
            ;;
    esac
}


case "$1" in
    "start")
        shift
        app_start $*
        ;;

	"stop")
        shift
		app_stop $*
		;;

	*)
		echo "$0 [start/stop]"
		;;
esac
