#!/bin/bash
# lldpd init file
#
# chkconfig: 2345 60 20
# description: 802.1ab (LLDP) daemon
#
# processname: lldpd
# pidfile: /var/run/lldpd.pid

### BEGIN INIT INFO
# Provides: lldpd
# Required-Start: $local_fs $network $remote_fs
# Required-Stop: $local_fs $network $remote_fs
# Should-Start: 
# Should-Stop: 
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: start and stop LLDP daemon
# Description: 802.1ab (LLDP) daemon
### END INIT INFO

# source function library
. /etc/rc.status

rc_reset

OPTIONS=""
if [ -e /etc/sysconfig/lldpd ]; then
  . /etc/sysconfig/lldpd
fi

RETVAL=0
prog="lldpd"
binary=/usr/sbin/lldpd
pidfile=/var/run/lldpd.pid
chroot=/var/run/lldpd


test -x $binary || { echo "LLDPD not installed"; 
	if [ "$1" = "stop" ]; then exit 0;
	else exit 5; fi; }


build_chroot()
{
        oldumask=$(umask)
        umask 022
        [ -d $chroot/etc ] || mkdir -p $chroot/etc
        [ -f $chroot/etc/localtime ] || [ ! -f /etc/localtime ] || \
                cp /etc/localtime $chroot/etc/localtime
        umask $oldumask
}


reload(){
        echo -n $"Reloading $prog: "
        killproc -p $pidfile $binary -HUP
        RETVAL=$?
        echo
        return $RETVAL
}

case "$1" in
  start)
        echo -n $"Starting $prog "
	build_chroot
        /sbin/startproc -p $pidfile $binary $OPTIONS
        rc_status -v
	;;
  stop)
	echo -n "Shutting down $prog "
	/sbin/killproc -TERM -p $pidfile $binary
	rc_status -v
	;;
  restart)
	$0 stop
	$0 start
	rc_status
        ;;
  reload)
	echo -n "Reload service $prog "
	/sbin/killproc -HUP -p $pidfile $binary
	rc_status -v
        ;;
  condrestart|try-restart)
	if test "$1" = "condrestart"; then
		echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
	fi
	$0 status
	if test $? = 0; then
		$0 restart
	else
		rc_reset
	fi
	rc_status
	;;
  status)
	echo -n "Checking for service $prog "
	/sbin/checkproc $prog
	rc_status -v
        ;;
  *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|reload}"
	exit 1
	;;
esac

rc_exit
