#!/bin/bash
#
# Init file for uptimed daemon
#
# chkconfig: 2345 95 05
# description: Uptimed is an uptime record daemon keeping track of the highest
#              uptimes a computer system ever had. It uses the system boot time
#              to keep sessions apart from each other. Uptimed comes with a
#              console front-end to parse the records, which can also easily be
#              used to show your records on a web page.
#
# config: /etc/uptimed.conf
#
### BEGIN INIT INFO
# Provides: uptimed
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Uptimed is an uptime record daemon
# Description: Uptimed is an uptime record daemon keeping track of the highest
#              uptimes a computer system ever had. It uses the system boot time
#              to keep sessions apart from each other. Uptimed comes with a
#              console front-end to parse the records, which can also easily be
#              used to show your records on a web page.
### END INIT INFO

RETVAL=0
NAME="uptimed"
UPTIMED="/usr/sbin/uptimed"

if [ -f /etc/rc.d/init.d/functions ]
then
	# Redhat
	. /etc/rc.d/init.d/functions
	START="daemon $UPTIMED"
	STOP="killproc $UPTIMED"
	STATUS="status $UPTIMED"
	CREATEBOOTID="action $\"Creating unique bootid for $NAME:\" $UPTIMED -b"
	POST="echo"
elif [ -f /sbin/start-stop-daemon ]
then
	# Debian
	START="start-stop-daemon --start --quiet --pidfile /var/run/uptimed.pid --exec $UPTIMED"
	STOP="start-stop-daemon --stop --quiet --pidfile /var/run/uptimed.pid --exec $UPTIMED"
	STATUS="echo \"Status not implemented\""
	CREATEBOOTID="echo \"Creating unique bootid for $NAME:\"; $UPTIMED -b"
	POST="echo \"$NAME.\""
else
	# Eep. What do we do here ?
	START="$UPTIMED"
	STOP="killall $UPTIMED"
	STATUS="echo \"Status not implemented\""
	CREATEBOOTID="$UPTIMED -b"
	POST="echo"
fi

start()
{
	echo -n $"Starting $NAME:"
	$START
	RETVAL=$?
	$POST
}

stop()
{
	echo -n $"Stopping $NAME:"
	$STOP
	RETVAL=$?
	$POST
}

showstatus()
{
	$STATUS $UPTIMED
	RETVAL=$?
}

createbootid()
{
	$CREATEBOOTID
	RETVAL=$?
	$POST
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	createbootid)
		createbootid
		;;
	status)
		showstatus
		;;
	*)
		echo $"Usage: $0 {start|stop|restart|createbootid|status}"
		RETVAL=1
esac
exit $RETVAL
