Pre-Command and Post-Command Job Conditions
When a job is being submitted, a pre-condition and/or a post-condition can be specified.
- pre-condition: a script that is executed before the job is executed.
- post-condition: a script that is executed after the job has completed. The post-condition is typically used to perform cleanup, such as deleting temporary files in /usr/tmp.
Example scripts are available in the following directories: $VOVDIR/etc/pre and $VOVDIR/etc/post.
Pre-condition
- If the precondition script fails by exiting with a status different from 0 (zero), the job will not be run and the exit status of the job will be the exit status of the pre-condition script.
- If the exit status of the pre-condition script is within the range 201-215, the automatic rescheduling condition will occur and the job will be rescheduled on a different host or on a different tasker (see more on auto-rescheduling).
Post-condition
- When the post-condition script is invoked, the job is still running.
- The post-condition is executed after the job, even if the job fails, but it is not executed if the pre-condition fails.
- The exit status of the post condition overrides the exit status of the job. It needs to explicitly return the exit status of the job when that is the requested behavior (see the example scripts).
Submit Jobs with Conditions
% nc run -pre $VOVDIR/etc/pre/pre_check.sh sleep 10
% nc run -post $VOVDIR/etc/post/post_cleanup.sh sleep 10
Log Files
The standard output from the pre- and post-commands is saved in log files. The location of the log files is determined by the value of the environment variable NC_LOGDIR. If NC_LOGDIR is not set, the files are stored in the directory ./vnc_logs, relative to the current launch directory.
[goetz@goetz1 ~/testrundir]$ pwd
/home/goetz/testrundir
[goetz@goetz1 ~/testrundir]$ ls
vnc_logs
[goetz@goetz1 ~/testrundir]$ ls -a vnc_logs/
. .. 20210726 .precmd.000083865.log .precmd.000083885.log snapshots
The log files are created with zero size if the pre- and post-commands redirect all the output of the files. At the end of the job, if these files are zero length, they are automatically deleted to reduce disk space overhead.
.precmd.$jobID.log
.postcmd.$jobID.log
nc run -pre "myprecommand > @JOBLOGDIR@/@JOBID@_pre.out" -l path/to/an/existing/directory/mycommand.out -- mycommand
nc run -post "mypostcommand > @JOBLOGDIR@/@JOBID@_post.out" -l path/to/an/existing/directory/mycommand.out -- mycommand