#!/bin/dash
# Entropy generator
# Description: Entropy generator for /dev/random - run continously. Either run this or haveged-boot, but not both.
# Note: if you enabled this, then disable haveged-boot

PIDFILE=/var/run/haveged.pid
PARAMS= # default is good enough

start() {
	haveged $PARAMS
}

stop() {
	if [ -f $PIDFILE ]; then
		read p < $PIDFILE
		kill $p	
	fi
}

is_running() {
	if [ -f $PIDFILE ]; then
		read p < $PIDFILE
		kill -0 $p
	else
		return 1
	fi
	
}

case $1 in
	start|restart)
		stop
		sleep 1
		start
		;;
		
	stop)
		stop
		;;
		
	status)
		is_running && echo "haveged is running" || echo "haveged is stopped"
		;;
esac
