#!/bin/sh
#
# Startup script for vm-pop3d
#
# chkconfig: 345 85 15
# description: vm-pop3d is a POP3 server with virtual domains support
# processname: pop3d

# Source function library.
. /usr/local/etc/rc.d/functions

PROG=/usr/local/sbin/vm-pop3d
LOCK=/var/spool/lock/vm-pop3d

RETVAL=0;

# See how we were called.
case "$1" in
  start)
	echo -n "Starting vm-pop3d: "
	daemon $PROG --daemon=18 -t 600
        RETVAL=$?
        if [ $RETVAL = 0 ] && touch $LOCK
        then
                echo -e "\t\t[ OK ]";
        else
                echo -e "\t\t[ FAILED ]";
        fi
	;;
  stop)
	echo -n "Stopping vm-pop3d: "
	#this will killing itself because the script is named vm-pop3d
	#killall vm-pop3d

	kill -9 `ps -x -o pid,command | grep $PROG | grep -v grep | cut -d\  -f1` 2> /dev/null

        RETVAL=$?
        if [ $RETVAL = 0 ] && rm -f $LOCK
        then
                echo -e "\t\t[ OK ]";
        else
                echo -e "\t\t[ FAILED ]";
        fi

	;;
  status)
	status vm-pop3d
	;;
  restart)
	$0 stop
	sleep 1
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|restart|status}"
	exit 1
esac

exit $RETVAL
