#!/bin/sh
#
# sysstat	Sysstat system monitoring utility
#
# chkconfig:	2345 35 65
#
# description:	Sysstat system monitoring tools (sar,iostat,mpstat)
#
# $Id: sysstat.init,v 1.14 2009/11/13 18:07:32 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_already_running "System Activity Data Collector"
		return
	fi

	msg_starting "System Activity Data Collector"
	daemon /usr/lib/sa/sadc $SADC_OPTIONS -
	RETVAL=$?
	[ "$RETVAL" -eq 0 ] && touch /var/lock/subsys/sysstat
}

stop() {
	if [ ! -f /var/lock/subsys/sysstat ]; then
		msg_not_running "System Activity Data Collector"
		return
	fi

	# Stop daemons.
	msg_stopping "System Activity Data Collector"
	ok
	rm -f /var/lock/subsys/sysstat >/dev/null 2>&1
}

condrestart() {
	if [ ! -f /var/lock/subsys/sysstat ]; then
		msg_not_running "System Activity Data Collector"
		RETVAL=$1
		return
	fi

	stop
	start
}

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
