#!/bin/bash

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

PORT=8022

case "$1" in
    start)
        stat_busy "Starting ajaxterm on port $PORT"
        /usr/bin/ajaxterm -p $PORT -d >/dev/null 2>/dev/null
        if [ $? -gt 0 ]; then
            stat_fail
        else
            add_daemon ajaxterm
            stat_done
        fi
        ;;
    stop)
        stat_busy "Stopping ajaxterm"
	[ -f /var/run/ajaxterm.pid ] && kill `cat /var/run/ajaxterm.pid`
        if [ $? -gt 0 ]; then
            stat_fail
        else
	    rm -f /var/run/ajaxterm.pid
            rm_daemon ajaxterm
            stat_done
        fi
        ;;
    restart)
        $0 stop
	sleep 1
        $0 start
        ;;
    *)
        echo "usage: $0 {start|stop|restart}"
	;;
esac
exit 0
