#!/bin/sh

PGPATH=/usr/ramdisk
DDNS=${PGPATH}/app/ddns/ipe_ddns

ddns_action()
{
        case "$1" in
        "start")
		ddns_enable="`${DDNS} -e`"
		if [ "${ddns_enable}" = "1" ]; then
                	${DDNS} -s &
                	echo "ipe_ddns is started!"
		else
			echo "ipe_ddns is disabled, not startup!"
		fi
                return 0
                ;;

        "stop")
                # kill monitor if it exists
                ps ax | grep ipe_ddns | awk '{print $1, $6}' | \
                while read pid path; do
                        if [ "${path}" = "${DDNS}" ]; then
                                kill -9 ${pid}
                                echo "ddns is stopped!"
                        fi
                done

                return 0
                ;;

        "*")
                echo "unknown action \"$1\""
                return 1
                ;;

        esac
}

if [ "$1" = "start" ]; then
	ddns_action "start"
elif [ "$1" = "stop" ]; then
	ddns_action "stop"
fi
