作业提交和执行控制行为
以下示例说明定制的 esub, epsub和 eexec 可执行文件如何控制作业提交和执行。
使用 esub 验证作业提交参数
当用户使用 bsub -P 命令选项提交作业时, LSF 接受用户输入的任何项目名称,并将该项目名称与作业相关联。 此示例显示了一个 esub ,它通过对有资格向这些项目收费的用户提交的作业强制使用有效项目名称来支持基于项目的记帐。 如果用户将作业提交到除 proj1 或 proj2以外的任何项目,或者如果用户名不是 user1 或 user2,那么 LSF 将根据退出值 LSB_SUB_ABORT_VALUE来拒绝该作业。
#!/bin/sh
. $LSB_SUB_PARM_FILE
# Redirect stderr to stdout so echo can be used for error messages exec 1>&2
# Check valid projects
if [ $LSB_SUB_PROJECT_NAME != "proj1" -o $LSB_SUB_PROJECT_NAME != "proj2" ]; then
echo "Incorrect project name specified"
exit $LSB_SUB_ABORT_VALUE
fi
USER=`whoami`
if [ $LSB_SUB_PROJECT_NAME="proj1" ]; then
# Only user1 and user2 can charge to proj1
if [$USER != "user1" -a $USER != "user2" ]; then
echo "You are not allowed to charge to this project"
exit $LSB_SUB_ABORT_VALUE
fi
fi
使用 esub 更改作业提交参数
以下示例显示根据提交作业的用户名修改作业提交选项和环境变量的 esub 。 此 esub 将更改写入 LSB_SUB_MODIFY_FILE for userA 和 LSB_SUB_MODIFY_ENVFILE for userB。 LSF 拒绝由 userC 提交的所有作业,而不写入任何一个文件:
#!/bin/sh
. $LSB_SUB_PARM_FILE
# Redirect stderr to stdout so echo can be used for error messages exec 1>&2
USER=`whoami`
# Make sure userA is using the right queue queueA
if [ $USER="userA" -a $LSB_SUB_QUEUE != "queueA" ]; then
echo "userA has submitted a job to an incorrect queue"
echo "...submitting to queueA"
echo 'LSB_SUB_QUEUE="queueA"' > $LSB_SUB_MODIFY_FILE
fi
# Make sure userB is using the right shell (/bin/sh)
if [ $USER="userB" -a $SHELL != "/bin/sh" ]; then
echo "userB has submitted a job using $SHELL"
echo "...using /bin/sh instead"
echo 'SHELL="/bin/sh"' > $LSB_SUB_MODIFY_ENVFILE
fi
# Deny userC the ability to submit a job
if [ $USER="userC" ]; then
echo "You are not permitted to submit a job."
exit $LSB_SUB_ABORT_VALUE
fi
使用 eexec 监视执行环境
此示例显示如何使用 eexec 来监视作业执行:
#!/bin/sh
# eexec
# Example script to monitor the number of jobs executing through RES.
# This script works in cooperation with an elim that counts the
# number of files in the TASKDIR directory. Each RES process on a host
# will have a file in the TASKDIR directory.
# Don’t want to monitor lsbatch jobs.
if [ "$LSB_JOBID" != "" ] ; then
exit 0
fi
TASKDIR="/tmp/RES_dir"
# directory containing all the task files
# for the host.
# you can change this to whatever
# directory you wish, just make sure anyone
# has read/write permissions.
# if TASKDIR does not exist create it
if [ "test -d $TASKDIR" != "0" ] ; then
mkdir $TASKDIR > /dev/null 2>&1
fi
# Need to make sure LS_JOBPID, and USER are defined
# exit normally
if [ "test -z $LS_JOBPID"="0" ] ; then
exit 0
elif [ "test -z $USER" = "0" ] ; then
exit 0
fi
taskFile="$TASKDIR/$LS_JOBPID.$USER"
# Fork grandchild to stay around for the duration of the task
touch $taskFile >/dev/null 2>&1
(
(while : ;
do
kill -0 $LS_JOBPID >/dev/null 2>&1
if [ $? -eq 0 ] ; then
sleep 10 # this is the poll interval
# increase it if you want but
# see the elim for its
# corresponding update interval
else
rm $taskFile >/dev/null 2>&1
exit 0
fi
done)&
)&
wait
使用 epsub 监视作业提交信息
此示例显示如何使用 epsub 来监视作业提交:
#!/bin/sh
# epsub
# Example script to monitor job submissions to mbatchd.
# This script outputs the final job submission parameters after the
# job is submitted.
exec 1>&2
. $LSB_SUB_PARM_FILE
echo I am epsub app >>/home/user1/epsub.out
echo $LSB_SUB_JOB_QUEUE t
echo $LSB_SUB_JOB_ID >> /home/user1/epsub.$LSB_SUB_JOB_ID
echo $LSB_SUB_JOB_ERR
在 esub 和 eexec 之间传递数据
esub 和 eexec 可执行文件的组合可用于将 AFS/DCE 令牌从提交主机传递到执行主机。 LSF 将数据从 esub 的标准输出传递到 eexec的标准输入。 可以使用守护程序包装程序脚本来更新令牌。