#!/usr/local/bin/bash
#
# Copyright (C) 2004 SIPfoundry Inc.
# Licensed by SIPfoundry under the LGPL license.
#
# Copyright (C) 2004 Pingtel Corp.
# Licensed to SIPfoundry under a Contributor Agreement.

Action=RUN
Status=0
Args=""

while [ $# -ne 0 ]
do
    case ${1} in
        --configtest)
            Action=CONFIGTEST
            ;;

        *)
            Args="$Args $1"
            ;;
    esac           

    shift # always consume 1
done

case ${Action} in
   RUN)
     echo $$ > /var/run/sipxpbx/watchdog.pid
     exec /usr/local/bin/watchdog $Args
     ;;

   CONFIGTEST)
        /usr/local/bin/sipx-validate-xml /usr/local/etc/sipxpbx/WatchDog.xml
        Status=$(($Status+$?))
        /usr/local/bin/sipx-validate-xml /usr/local/etc/sipxpbx/ProcessDefinitions.xml
        Status=$(($Status+$?))
        for procspec in /usr/local/etc/sipxpbx/process.d/*.process.xml
        do
          /usr/local/bin/sipx-validate-xml $procspec
          Status=$(($Status+$?))
        done
        ;;
esac

exit $Status
