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/post and $VOVDIR/etc/pre.

Pre-condition

A pre-condition is executed before the job is run. A pre-condition is executed with the same credentials as the job (userid, os-groupid) and is in the same directory of the job.
  • 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

The post-condition script is invoked with two arguments: the ID of the job and the exit status of the job. The post-condition is executed with the same credentials as the job (userid, os-groupid) and in the same directory of the job.
  • 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 does not affect the exit status of the job.

Submit Jobs with Conditions

Use the options -pre and -post with nc run to specify the pre- and post- conditions.
% nc run -pre $VOVDIR/etc/pre/pre_check.csh sleep 10
% nc run -post $VOVDIR/etc/post/post_cleanup.csh sleep 10

Log Files

The standard output from the pre- and post-commands is saved in log files in the run directory; standard error is discarded. These 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.

The log files are named according to the following rules:
.precmd.$jobID.log
.postcmd.$jobID.log
The pre- and post-command log files can optionally be located in the same directory as the job logfile. For example:
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
This would result in the respective pre- and post-command logfiles being written to the directory path/to/an/existing/directory.
Note: When using the nc run command after forgetting jobs that have pre- and/or post-commands, it does not automatically remove the pre- and post-command .log files. If these files are not zero length, they must be removed manually.