aqualaguna's picture
Add files using upload-large-folder tool
4a1ea7b verified
Raw History Blame Contribute Delete
1.29 kB
#!/bin/bash
# runjob.sh NAME GPU(0|1) TAG cmd-args... (runs inside CT 140)
# CPU job: systemd-run scope, OOMScoreAdjust=1000, MemoryMax.
# GPU job: same, but under `flock /run/b60-gpu.lock` (shared with the other B60 agent); waits if the lock is held.
# stdout/stderr -> /opt/mossimage/logs/NAME.log ; exit code -> NAME.rc
NAME=$1; GPU=$2; TAG=$3; shift 3
LOG=/opt/mossimage/logs/$NAME.log
export MOSS_RUN_TAG=$TAG
export PYTHONUNBUFFERED=1
cd ${CODE_DIR:-/opt/mossimage/code}
rm -f /opt/mossimage/logs/$NAME.rc
# `systemd-run --scope -p OOMScoreAdjust=` is rejected by this systemd ("Unknown assignment"); set it via /proc in the wrapper
SCOPE="systemd-run --scope -q --collect -p MemoryMax=${MEMMAX:-30G} /opt/mossimage/code/oomwrap.sh"
touch /run/b60-gpu.lock
# a *.sh first argument runs under bash instead of python (GPU=2: the script takes the card lock itself, so no outer flock here)
case "$1" in *.sh) RUN="bash";; *) RUN="/opt/mossimage/venv/bin/python -u";; esac
if [ "$GPU" = 1 ]; then
echo "[runjob] $(date +%T) waiting for /run/b60-gpu.lock" > $LOG
flock /run/b60-gpu.lock $SCOPE $RUN "$@" >> $LOG 2>&1
else
$SCOPE $RUN "$@" > $LOG 2>&1
fi
echo $? > /opt/mossimage/logs/$NAME.rc
echo "[runjob] $(date +%T) finished rc=$(cat /opt/mossimage/logs/$NAME.rc)" >> $LOG