Lucasgitguy-co's picture
Turbo-Kev Dictate release
20149a3 verified
Raw History Blame Contribute Delete
1.16 kB
#!/bin/bash
# run_bg.sh <name> <command...>: run a long job detached (nohup + setsid + caffeinate) so terminal/Claude restarts
# can't kill it. launchd is not used: launchd jobs get "Operation not permitted" on this removable exFAT drive (no
# Removable Volumes permission). Log: runs/<name>-<time>.log, ends with EXIT=<code>. PID (= process group) in
# runs/<name>.pid. Save and stop training: bash run.sh stop
set -euo pipefail
cd "$(dirname "$0")"
if [[ $# -lt 2 || ! "$1" =~ ^[a-zA-Z0-9_.-]+$ ]]; then
echo "Usage: ./run_bg.sh <job-name> <command> [args...]" >&2
exit 2
fi
name=$1; shift
if [[ ${1##*/} == bash && ( ${2:-} == run.sh || ${2:-} == ./run.sh ) ]]; then
case ${3:-} in
chain|text|proj)
export PYTHONPATH="$PWD"
exec "${TK_PY:-$HOME/.venvs/turbo-kev-train/bin/python}" -m tk.control background "$name" "$@"
;;
esac
fi
log="$PWD/runs/$name-$(date +%Y%m%d-%H%M%S).log"
nohup perl -e 'use POSIX qw(setsid); setsid(); exec @ARGV' /bin/bash -c 'caffeinate -i "$@"; code=$?; echo EXIT=$code; exit "$code"' bash "$@" \
> "$log" 2>&1 < /dev/null &
echo $! > "runs/$name.pid"; disown
echo "started $name pid $! -> $log"