extensions/net.sf.basedb.opengrid/trunk/src/net/sf/basedb/opengrid/engine/sge/run.sh

Code
Comments
Other
Rev Date Author Line
6629 07 Mar 22 nicklas 1 #!/bin/bash
6629 07 Mar 22 nicklas 2 ##
6629 07 Mar 22 nicklas 3 ## This script is a wrapper before starting the actual job.
6629 07 Mar 22 nicklas 4 ## It will setup working and temporary directories and
6629 07 Mar 22 nicklas 5 ## error handlers for aborting and exiting in a well-defined fashion
6629 07 Mar 22 nicklas 6 ##
6629 07 Mar 22 nicklas 7
6629 07 Mar 22 nicklas 8 ## This function is executed when the script exits
6629 07 Mar 22 nicklas 9 cleanupOnExit()
6629 07 Mar 22 nicklas 10 {
6629 07 Mar 22 nicklas 11   EXIT_CODE=$?
6629 07 Mar 22 nicklas 12   ## Remove temporary directory unless debugging
6629 07 Mar 22 nicklas 13   cd ${WD}
6629 07 Mar 22 nicklas 14   if [ -z "${JOB_DEBUG}" ] && [ -d "${TMPDIR}" ]; then
6629 07 Mar 22 nicklas 15     rm -rf ${TMPDIR}
6629 07 Mar 22 nicklas 16   fi
6629 07 Mar 22 nicklas 17 }
6629 07 Mar 22 nicklas 18
6629 07 Mar 22 nicklas 19 ## Add handler for cleaning up after the job has ended
6629 07 Mar 22 nicklas 20 trap cleanupOnExit EXIT
6629 07 Mar 22 nicklas 21
7379 18 Oct 23 nicklas 22 ## Create temporary directory and ensure that it is empty (unless debugging)
6629 07 Mar 22 nicklas 23 mkdir -p ${TMPDIR}
7379 18 Oct 23 nicklas 24 if [ -z "${JOB_DEBUG}" ]; then
7379 18 Oct 23 nicklas 25   rm -rf ${TMPDIR}/*
7379 18 Oct 23 nicklas 26 fi
6629 07 Mar 22 nicklas 27
6629 07 Mar 22 nicklas 28 ## Finally, we can now run the actual job
6629 07 Mar 22 nicklas 29 cd ${WD}
6629 07 Mar 22 nicklas 30 ./job.sh
6629 07 Mar 22 nicklas 31 JOB_EXIT_CODE=$?
6629 07 Mar 22 nicklas 32
6629 07 Mar 22 nicklas 33 ## Exit with the exit code from the job
6629 07 Mar 22 nicklas 34 ## (not really needed in the current implementation since job.sh is the last cmd)
6629 07 Mar 22 nicklas 35 exit ${JOB_EXIT_CODE}