1#!/bin/sh23set -e45: ${varsh_memlimit:="10KiB"}6: ${varsh_maxprocs:="1"}7# TODO: varshell cpu and timeout89function msg() {10 local color=${2:-green}11 case "$color" in12 red) color="31";;13 green) color="32";;14 yellow) color="33";;15 blue) color="34";;16 gray) color="37";;17 *) color="32";;18 esac19 printf "\033[1;%sm>>>\033[1;0m %s\n" "$color" "$1" | xargs >&220}2122function fatal() {23 msg "$1" red24 exit 125}2627cifile=$(mktemp)28trap 'rm -f $cifile' EXIT29cat > $cifile3031run() {32 local fname=$133 (34 cleanup_cmds=""35 trap 'eval "$cleanup_cmds"' EXIT3637 varfile=$(mktemp)38 cleanup_cmds="$cleanup_cmds39 rm -f $varfile"40 GOMAXPROCS="$varsh_maxprocs" GOMEMLIMIT="$varsh_memlimit" varshell -f "$fname" "$cifile" > $varfile41 . $varfile4243 msg "${fname:+[$fname]} job starting"4445 if [ -n "$depends" ]; then46 msg "${fname:+[$fname]} depends $depends"47 for dep in "$depends"; do48 run $dep49 done50 fi5152 source @sharedir@/$worker_type53 ${worker_type}_start54 cleanup_cmds="$cleanup_cmds55 ${worker_type}_stop"565758 msg "${fname:+[$fname]} entrypoint running"59 {60 cat $cifile61 echo $'\n'$entrypoint62 } | ${worker_type}_runcmd63 msg "${fname:+[$fname]} job ended"64)}6566run