Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/spark-supervisor/blob/main/tests/twin.sh # spark-supervisor Process supervisor and health monitor for sovereign daemons Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `spark-supervisor / tests / twin.sh` 36 lines ยท 1892 bytes Raw Blame History 1 #!/bin/sh 2 # twin.sh: run an isolation probe inside an installed service's exact sandbox. Root only: 3 # sudo -n sh tests/twin.sh SERVICE PROBE.py [ARGS...] [-- EXTRA_FILE...] 4 # Copies /etc/aien-supervise/services/SERVICE.svc to SERVICE-twin.svc with only these changes: 5 # the exec line runs `python3.12 -I /opt/aien-sup-twin/PROBE.py ARGS`, watch/restart/type lines 6 # become `type oneshot` + `restart no`, and /opt/aien-sup-twin is bound read-only. User, groups, 7 # binds, network rules, cgroup limits and the syscall filter are the service's own. The probe and 8 # any EXTRA_FILE are copied into /opt/aien-sup-twin (root-owned). The twin's nftables table (same 9 # uid rules as the service) and the twin file are removed afterwards. Exit status: the probe's. 10 set -u 11 [ "$(id -u)" = 0 ] || { echo "twin.sh: run as root" >&2; exit 2; } 12 [ $# -ge 2 ] || { echo "usage: twin.sh SERVICE PROBE.py [ARGS...] [-- EXTRA_FILE...]" >&2; exit 2; } 13 svc=$1; probe=$2; shift 2 14 S=/etc/aien-supervise/services 15 D=/opt/aien-sup-twin 16 H=/usr/local/libexec/aien-supervise/aien-supervise-root 17 [ -f "$S/$svc.svc" ] || { echo "twin.sh: no $S/$svc.svc" >&2; exit 2; } 18 args=""; extra=""; inextra=0 19 for a in "$@"; do 20 if [ "$a" = -- ]; then inextra=1; continue; fi 21 if [ $inextra = 1 ]; then extra="$extra $a"; else args="$args $a"; fi 22 done 23 install -d -o root -g root -m 0755 "$D" 24 install -o root -g root -m 0644 "$probe" "$D/$(basename "$probe")" 25 for f in $extra; do install -o root -g root -m 0644 "$f" "$D/$(basename "$f")"; done 26 twin=$svc-twin 27 trap 'rm -f "$S/$twin.svc"; nft delete table inet "aiens_$(echo "$twin" | tr - _)" 2>/dev/null; rm -rf "$D"' EXIT 28 { 29 grep -vE '^(exec|watch|restart|type|every|delay|timeout) ' "$S/$svc.svc" 30 echo "exec /usr/bin/python3.12 -I $D/$(basename "$probe")$args" 31 echo "type oneshot" 32 echo "restart no" 33 echo "ro $D" 34 } > "$S/$twin.svc" 35 chmod 0644 "$S/$twin.svc" 36 "$H" run "$twin"