self-hosted/install/error-handling.sh
2021-11-30 16:55:56 -05:00

36 lines
775 B
Bash

echo "${_group}Setting up error handling ..."
# Courtesy of https://stackoverflow.com/a/2183063/90297
trap_with_arg() {
func="$1" ; shift
for sig ; do
trap "$func $sig "'$LINENO' "$sig"
done
}
DID_CLEAN_UP=0
# the cleanup function will be the exit point
cleanup () {
if [[ "$DID_CLEAN_UP" -eq 1 ]]; then
return 0;
fi
DID_CLEAN_UP=1
if [[ "$1" != "EXIT" ]]; then
echo "An error occurred, caught SIG$1 on line $2";
if [[ -n "$MINIMIZE_DOWNTIME" ]]; then
echo "*NOT* cleaning up, to clean your environment run \"docker compose stop\"."
else
echo "Cleaning up..."
fi
fi
if [[ -z "$MINIMIZE_DOWNTIME" ]]; then
$dc stop -t $STOP_TIMEOUT &> /dev/null
fi
}
trap_with_arg cleanup ERR INT TERM EXIT
echo "${_endgroup}"