#!/bin/bash
#
# rngd        This starts and stops rngd
#
# chkconfig: - 13 99
# description: This starts the Random Number Generator Daemon, \
#              which collects entropy from hardware sources and \
#              write it to /dev/random
#
# processname: /usr/sbin/rngd
# config: /etc/sysconfig/rngd
# pidfile: /var/run/rngd.pid
#
# Return values according to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#


PATH=/sbin:/bin:/usr/bin:/usr/sbin
PROG="rngd"
CMD="/usr/sbin/$PROG"
LOCK_FILE="/var/lock/$PROG"
PID_FILE="/var/run/$PROG.pid"

# Source function library.
. /lib/lsb/init-functions

# Allow anyone to run status
if [ "$1" = "status" ] ; then
	status $PROG
	RETVAL=$?
	exit $RETVAL
fi

# Check that we are root ... so non-root users stop here
test $EUID = 0  ||  exit 4

# Check config
test -f /etc/sysconfig/$PROG && . /etc/sysconfig/$PROG

RETVAL=0

start()

{
test -x $CMD  || exit 5

log_info_msg "Starting $PROG: "
unset HOME MAIL USER USERNAME
start_daemon $CMD $EXTRAOPTIONS 2> /dev/null
evaluate_retval
touch $LOCK_FILE
}

stop()

{
if [ -f $LOCK_FILE ] ; then
  log_info_msg "Stopping $PROG: "
  killproc -p $PID_FILE $CMD
  evaluate_retval
  rm -f $LOCK_FILE
  fi
}

reload()

{
stop
start
}

restart()

{
stop
start
}

condrestart()

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


# See how we were called.
case "$1" in
    start)
	start
	;;
    stop)
	stop
	;;
    restart)
	restart
	;;
    reload|force-reload)
	reload
	;;
    condrestart|try-restart)
	condrestart
	;;
    *)
	echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
	RETVAL=3
esac

