Usage: catch-fail op
catch-fail is used to help debug a melange build. In a 'run' section
you can add at the top:
eval $(/home/build/catch-fail eval-trap 1h)
And then if the section fails it will block for 1 hour so that
from the outside you can run
catch-fail enter
Last active
February 14, 2024 15:36
-
-
Save smoser/84909431c72e6409251c8897ac816872 to your computer and use it in GitHub Desktop.
catch-fail - trap failure and sleep so as to enter a melange build for dbug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# vi: ts=4 expandtab | |
# https://gist.github.com/smoser/84909431c72e6409251c8897ac816872 | |
Usage() { | |
local me=${0#**/} | |
cat <<EOF | |
Usage: $me op | |
This is tested with bubblewrap (bwrap) backend. | |
It will need adjusting for docker or other backend. | |
The setgid and setuid values probably need changing on other system. | |
$me is used to help debug a melange build. In a 'run' section | |
you can add at the top: | |
eval \$(/home/build/catch-fail eval-trap 1h) | |
And then if the section fails it will block for 1 hour so that | |
from the outside you can run | |
$me enter | |
EOF | |
} | |
case "$1" in | |
enter) | |
p=$(ps axww | awk '/CATCH-FAIL/ { print $1; exit; }'); | |
( [ -n "$p" ] || { echo "no pid found"; exit 1; }; | |
echo pid=$p; sudo nsenter -a --setgid 1002 --setuid 1001 -t $p /bin/sh ) | |
;; | |
eval-trap) | |
p='rc=$?; [ $rc -eq 0 ] || '\"$0\"' CATCH-FAIL '\"${2:-30m}\"' $rc' | |
echo trap "'$p'" EXIT | |
;; | |
-h|--help) | |
Usage | |
exit | |
;; | |
CATCH-FAIL) | |
nap=${2:-30m} | |
rc=${3:-"-1"} | |
sleep ${nap} & | |
pid=$! | |
echo "============ section failed with rc $rc ===============" | |
echo "============ sleeping for $nap in $pid ================" | |
echo "I am: $(id)" | |
echo "I had $# args: $*" | |
wait $pid | |
;; | |
*) Usage 1>&2; | |
exit 1;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment