#!/bin/sh

. /etc/sysconfig/rc.conf
. /bin/network-functions

SETSID=/usr/bin/setsid
PIDFILE=/var/run/sch_voice_restarter.pid
SERVICE=sch_voice_restarter
PROCESS_NAME=sch_voice_restarter

do_start ()
{
    if ! ServiceCheckRunning1 ; then
        return $?
    fi

    /etc/init.d/softdogd wait
    $SETSID /bin/$PROCESS_NAME > /dev/null 2>&1 &
    echo $! > $PIDFILE

    ServiceCheckRunning2

    /bin/sleep 2
    getprocess=`ps -ef|grep $PROCESS_NAME`
    set $getprocess
    pid=$2
    echo $pid > $PIDFILE

    return
}

do_stop ()
{
    /etc/init.d/softdogd wait
	/bin/killall $PROCESS_NAME > /dev/null
    ServiceStop

    return $?
}

do_status ()
{
    ServiceStatus

    return $?
}

case "$1" in
        start)
            do_start
            ;;
        stop)
            do_stop
            ;;
        restart)
            do_stop
            /bin/usleep 500
            do_start
            ;;
        status)
            do_status
            ;;
        *)
            echo "Usage: $0 {start|stop|restart|status}"
            exit 1
esac

exit $?
