#!/bin/sh
# Startup script for ntlmaps
#
# chkconfig: 345 95 05
# description: NTLMAPS proxy service

# Author: Pavel Starek
# License: GPL


# Source function library.
. /etc/rc.d/init.d/functions

# test for exist main "binary" file
[ -f /opt/ntlmaps/main.py ] || exit 0

prog0="ntlmaps"

start() {

    if [ -f /var/lock/subsys/ntlmaps ] ; then
      echo "Service $prog0 already running"
      exit 0
    fi
    echo
    echo -n $"Starting $prog0: " 
    /usr/bin/python /opt/ntlmaps/main.py &
    echo $! >/var/run/ntlmaps.pid
    RETVAL=0
    touch /var/lock/subsys/ntlmaps
    echo
    return $RETVAL
}

stop() {

    if [ -f /var/lock/subsys/ntlmaps ] ; then
      echo
      echo -n $"Stopping $prog0: "
      killproc $prog0
      rm -f /var/run/ntlmaps.pid
      rm -f /var/lock/subsys/ntlmaps
      RETVAL=0
      echo
      return $RETVAL
    fi

}

status() {

  if [ -f /var/lock/subsys/ntlmaps ] ; then
    read ntlmapspid < /var/run/$prog0.pid
    echo $"$prog0 is running and fully functional with process ID: $ntlmapspid"
  else
    echo $"$prog0 not running ... bad idea !!!"
  fi
      
}

case "$1" in
	start)
	    start
	    ;;
	
	stop)
	    stop
	    ;;
	
	status)
            status
	    ;;

	restart)
	    stop
	    start
	    ;;
	*)
	    echo $"Usage: $0 {start|stop|restart|status}"
	    exit 1

esac

exit $RETVAL

