#!/bin/sh
#=================================================================
# Begin tftpd
#
# Description:	Start in.tftpd daemon
# chkconfig:	2345 95 18
#
#=================================================================

### BEGIN INIT INFO
# Provides:            $tftpd
# Required-Start:      $iptables $network
# Should-Start:        $syslog
# Required-Stop:       
# Should-Stop:         $syslog
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Short-Description:   Starts and stops tftpd daemon
# Description:         Starts and stops tftpd daemon, a bootless protocol
### END INIT INFO

. /lib/lsb/init-functions

RETVAL=0
PROG="in.tftpd"
CMD="/usr/sbin/$PROG"
TFTPDIR="/usr/share/syslinux"
PID_FILE="/var/run/$PROG.pid"
OPTIONS="-l -P $PID_FILE -s $TFTPDIR -vvv"

# Some functions to make the below more readable
case "$1" in
    start)
      log_info_msg "Starting $PROG daemon..."
      start_daemon $CMD $OPTIONS > /dev/null 2>&1
      evaluate_retval
      ;;

    stop)
	if [ -f $PID_FILE ] ; then
          log_info_msg "Stopping $PROG Server..."
          killproc -p $PID_FILE $CMD
          evaluate_retval
  	  fi
        ;;

    reload)
        log_info_msg "Reloading $PROG Server..."
        pid=`cat $PID_FILE 2>/dev/null`
        if [ -n "${pid}" ]; then
           kill -HUP "${pid}"
        else
           (exit 1)
        fi
        evaluate_retval
        ;;

    restart)
        $0 stop
        sleep 1
        $0 start
        ;;

    condrestart)
        pid=`cat $PID_FILE 2>/dev/null`
        if [ -n "${pid}"  -a -d /proc/$pid ]; then
	  $0 restart
	  fi
        ;;

    status)
        statusproc -p $PID_FILE $PROG
        ;;

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

