#!/bin/bash

# general config
. /etc/rc.conf
. /etc/rc.d/functions

PID="$(pidof -o %PPID /usr/sbin/mISDNcapid)"
case "$1" in
    start)
        stat_busy "Starting misdncapid"
	if [ ! -x /var/run/mISDNcapid ] ; then
	    install -m755 -d /var/run/mISDNcapid
	fi

	[ -z "$PID" ] && /usr/sbin/mISDNcapid >/dev/null 2>&1
        if [ $? -gt 0 ]; then
            stat_fail
        else
            PID=$(pidof -o %PPID /usr/sbin/mISDNcapid)
            echo $PID > /var/run/misdncapid.pid
            add_daemon misdncapid
            stat_done
        fi
        ;;
    stop)
        stat_busy "Stopping misdncapid"
	[ -f /var/run/misdncapid.pid ] && kill `cat /var/run/misdncapid.pid` >/dev/null 2>&1
        if [ $? -gt 0 ]; then
            stat_fail
        else
	    rm -f /var/run/misdncapid.pid
            rm_daemon misdncapid
            stat_done
        fi
        ;;
    restart)
        $0 stop
	sleep 1
        $0 start
        ;;
    *)
        echo "usage: $0 {start|stop|restart}"
	;;
esac
exit 0
