case "$1" in
        start)
                sleep 5
                /usr/local/sbin/pptp 10.0.0.138 MXSTREAM &
                echo -n ' mxstream'
                ;;

        test)
                if [ \! -e /var/run/pptp/10.0.0.138 ]; then
                        echo "Detected graceful PPTP client shutdown."
                        echo ""
                        echo "Restarting mxstream connection at `date`."
                        /usr/local/etc/rc.d/mxstream.sh stop  > /dev/null
                        /usr/local/etc/rc.d/mxstream.sh start > /dev/null
                elif [ -e /pptp.core ]; then
                        echo "Detected PPTP client core."
                        ls -l /pptp.core
                        echo ""
                        echo "Restarting mxstream connection at `date`."
                        /usr/local/etc/rc.d/mxstream.sh stop > /dev/null
                        /usr/local/etc/rc.d/mxstream.sh start > /dev/null
                fi
                ;;

        stop)
                /usr/bin/killall ppp
                /usr/bin/killall pptp
                rm -rf /var/run/pptp /pptp.core
                echo -n ' mxstream'
                ;;

        *)
                echo "Usage: `basename $0` { start | test | stop }"
                echo "  start: Open the mxstream connection."
                echo "  test:  Test for pptp-client failure and reopen the connection if necessary."
                echo "  stop:  Close the mxstream connection."
                exit 64
                ;;
esac

