#! /bin/sh
# Copyright (c) 2000-2003 SuSE GmbH Nuernberg, Germany.
#
# /etc/init.d/sysstat
#
### BEGIN INIT INFO
# Provides:          
# Required-Start:    boot.rootfsck boot.cleanup boot.clock
# Should-Start:      $local_fs
# Required-Stop:
# Default-Start:     B
# Default-Stop:
# Short-Description: Write information about system start to sysstat log
# Description:       Write information about system start to sysstat log
### END INIT INFO

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

. /etc/rc.status
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - misc error
# 2 - invalid or excess args
# 3 - unimplemented feature (e.g. reload)
# 4 - insufficient privilege
# 5 - program not installed
# 6 - program not configured
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.

case "$1" in
    start)
        echo "Running sadc"
	/usr/lib64/sa/sa1 1>/dev/null 2>&1 \
		&& ln -fs /etc/sysstat/sysstat.cron /etc/cron.d/sysstat \
		|| rc_failed 1
	rc_status -v
	;;

    stop)
	echo "Removing sysstat's crontab"
	rm -f /etc/cron.d/sysstat
	rc_status -v
	;;

    check|status)
        echo -n "Checking for service sysstat: "
        test -L /etc/cron.d/sysstat \
                && test "`readlink /etc/cron.d/sysstat`" == /etc/sysstat/sysstat.cron \
		|| rc_failed 3
        rc_status -v
	;;

    restart|reload|probe)
        rc_failed 3
        ;;	

    *)
	echo "Usage: $0 {start|stop|status}"
	exit 1
	;;
esac
rc_exit
