#!/bin/sh
#
#
# (c) 2002 Sun Microsystems, Inc. Use is subject to license terms.  

# change the path to your needs
F=/tmp/restart.out
touch $F

echo ----------------------------------  >> $F 2>&1
echo I am: `id`				 >> $F 2>&1
echo Checkpoint command called at `date` >> $F 2>&1
echo Myargs: $*				 >> $F 2>&1
echo done				 >> $F 2>&1
echo                                     >> $F 2>&1

echo Restart command: /usr/bin/restart sge_$1 >> $F 2>&1
/usr/bin/restart -j -m sge_$1                 >> $F 2>&1

# Now be careful: The restart command is the parent process of the restarted
# job. SGE is the parent process of the restart command.
# If the job was killed (probably due to a migration request), we need to
# tell our parent that by killing ourselves. SGE will also detect an 
# exit status > 128 analogous to a KILL

exit_status=$?
echo Exit status of restart command: $exit_status >> $F 2>&1

# This doesn't work under Irix 6.2, since the variable $$ is not
# correctly set
#if [ $exit_status -gt 128 ]; then
#   signal=`expr $exit_status - 128`
#   echo Killing ourself: kill -$signal $$        >> $F 2>&1   
#   /usr/bin/kill -$signal $pid                   >> $F 2>&1
#fi

# If killing ourselves didn't help or the exit_status was  < 128 exit 
# with the exit status of our child

echo Exiting with exit status: $exit_status      >> $F 2>&1
exit $exit_status
