#! /bin/bash
#
# monitor-memory          Activate/deactivate memory logging
#
# Source function library.

BASE_SCRIPT=/opt/xensource/libexec/monitor-memory
BASE_CRON_FILE=/opt/xensource/libexec/monitor-memory-cron
ACTIVATE_MODE=644

. /etc/init.d/functions

rhstatus() {
	if [ -e ${ACTIVATE_CRON} ]; then
           echo Memory logging is active
        else
           echo Memory logging is inactive
        fi
}	

restart() {
  	stop
	start
}	

activate() {
	cat ${BASE_CRON_FILE} >> /etc/crontab
	service crond stop
	service crond start
}

deactivate() {
	grep -v ${BASE_SCRIPT} /etc/crontab > /tmp/crontab.new
	mv /tmp/crontab.new /etc/crontab
	service crond stop
	service crond start
}

case "$1" in
  activate)
  	activate
	;;
  status)
  	rhstatus
	;;
  deactivate)
        deactivate
        ;;
  *)
	echo $"Usage: $0 {activate|deactivate|status|reload}"
	exit 1
esac
