#!/bin/rc

# not actually a cron job
# this script runs regupdate, svcupdate, regrepair, svcrepair periodically

echo gridmaint started on 10 minute cycle
echo warning - if you have a very bad net connection
echo this script may produce a lot of dead processes on your and other nodes
while (test -e /tmp/grid/info/gridsession) {
	echo `{date} gridmaint cycle start >>/tmp/grid/log/log
	g/regupdate >>/tmp/grid/log/gridcron &
	sleep 120
	g/svcupdate >>/tmp/grid/log/gridcron &
	sleep 120
	g/regrepair >>/tmp/grid/log/gridcron &
	sleep 120
	g/svcrepair >>/tmp/grid/log/gridcron &
	sleep 240

# if stuff is getting stuck, bail out and warn the user

	if (test -e /tmp/grid/work/maintest) rm /tmp/grid/work/maintest
	touch /tmp/grid/work/maintest
	ps -a |grep regupdate |grep -v grep >>/tmp/grid/work/maintest
	ps -a |grep svcupdate |grep -v grep >>/tmp/grid/work/maintest
	ps -a |grep regrepair |grep -v grep >>/tmp/grid/work/maintest
	ps -a |grep svcrepair |grep -v grep >>/tmp/grid/work/maintest
	MAINTEST = `{cat /tmp/grid/work/maintest}
	if (~ $MAINTEST ??*){
		echo maintenance process may be stuck, manual repair or gridrebuild is needed
		exit
	}
	rm /tmp/grid/work/maintest
} &
