Skip to content
Snippets Groups Projects
  • John-Paul Robinson's avatar
    Add FILEPATH var to pass to policy scripts · 7950f920
    John-Paul Robinson authored
    Add variable arg to mmapplypol to pass the filesystem path as FILEPATH.
    The supports policies that want to use this variable in their rules
    or other parts of the policy file.
    It is a strict string substitution.
    7950f920
run-mmpol.sh 970 B
#!/bin/bash

# run an mmapply policy across the cluster via slurm

# gather info to map mmapplypolicy to runtime configuration
# arguments passed via job env and runtime context

filesystem=${FILESYSTEM:-scratch}
policyfile=$POLICYFILE
tmpglobal=$DIR
tmpscratch=$DIR

nodes=`scontrol show hostnames "${SLURM_JOB_NODELIST}" | tr '\n' ',' | sed -e 's/,$//'`
cores="${SLURM_CPUS_PER_TASK}"

DATESTR=`date +'%Y-%m-%d-%H:%M:%S'`

policy=`basename $policyfile`
filetag="${policy}_slurm-${SLURM_JOBID}_${DATESTR}"

cmd="mmapplypolicy ${filesystem} -I prepare \
  -P $policyfile \
  -g $tmpglobal \
  -s $tmpscratch \
  -M FILEPATH=${filesystem} \
  -N ${nodes} -n ${cores}"

# report final command in job log
echo $cmd

# run policy command
$cmd

rcode=$?

if [ $rcode -ne 0 ]
then
  echo error: mmapplypoicy failed: code $rcode
  exit $rcode
fi

# tag output file with run metadata
outfile=`ls -t $tmpglobal | head -1`
mv -n $tmpglobal/$outfile $tmpglobal/${outfile}_$filetag