#!/bin/sh
#
# sysstat	Sysstat system monitoring utility
#
# chkconfig:	2345 35 65
#
# description:	Sysstat system monitoring tools (sar,iostat,mpstat)
#
# $Id: sysstat.init,v 1.13 2008/11/04 20:47:09 glen Exp $

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

[ -f /etc/sysconfig/sysstat ] && . /etc/sysconfig/sysstat

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/sysstat ]; then
		msg_starting "system activity data collector"
		daemon /usr/lib/sa/sadc $SADC_OPTIONS -
		RETVAL=$?
		[ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/sysstat
	else
		msg_already_running "system activity data collector"
	fi
}

stop() {
	if [ -f /var/lock/subsys/sysstat ]; then
		# Stop daemons.
		msg_stopping "system activity data collector"
		ok
		rm -f /var/lock/subsys/sysstat >/dev/null 2>&1
	else
		msg_not_running "system activity data collector"
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/sysstat ]; then
		stop
		start
	else
		msg_not_running "system activity data collector"
		RETVAL=$1
	fi
}

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

exit $RETVAL
