#!/bin/sh
#
# tuptime - Historical and statistical real time of the system.
#
# chkconfig:   12345  25  90
# description: Report the historical and statistical real time  \
#              of the system, keeping it between restarts. 

### BEGIN INIT INFO
# Provides: tuptime
# Required-Start: $local_fs $time
# Required-Stop: $local_fs $time
# Short-Description: start and stop tuptime
# Description: Report the historical and statistical real time
#  of the system, keeping it between restarts.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

USER='_tuptime'
BIN_NAME='tuptime'
PATH_BIN="/usr/bin/$BIN_NAME"
LOCKFILE="/var/lock/subsys/$BIN_NAME"
RETVAL=0

do_start () {
        # Start service
        echo -n $"Starting tuptime: "
        daemon --user $USER $PATH_BIN -x
        RETVAL=$?
         echo
        [ $RETVAL -eq 0 ] && touch ${LOCKFILE}
        return $RETVAL
}

do_stop () {
        # Stop service
        echo -n $"Stopping tuptime: "
        daemon --user $USER $PATH_BIN -xg
        $PATH_BIN -xg
        RETVAL=$?
         echo
        [ $RETVAL -eq 0 ] && rm -f ${LOCKFILE}
        return $RETVAL
}

do_status () {
        # Status service
        $PATH_BIN
}


case "$1" in
  start|"")
        do_start
        ;;
  restart)
        do_stop
        do_start
        ;;
  stop)
        do_stop
        ;;
  status)
        do_status
        exit $?
        ;;
  *)
        echo "Usage: $BIN_NAME [start|stop|restart|status]" >&2
        exit 3
        ;;
esac
