mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-05-31 04:44:05 +02:00
Fix E2BIG error in ha_entrypoint.sh: add source fallback when exec fails with rc=126
When the environment is too large for exec (E2BIG), scripts fail with 'env: can't execute bashio: Argument list too long'. This adds a fallback that sources the script in a subshell with bashio preloaded, avoiding exec entirely. Applied to both init scripts and service runners. Co-authored-by: alexbelgium <44178713+alexbelgium@users.noreply.github.com>
This commit is contained in:
@@ -165,6 +165,26 @@ if [ -z "$shebang" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
####################################
|
||||||
|
# Bashio library for source fallback
|
||||||
|
####################################
|
||||||
|
|
||||||
|
BASHIO_LIB=""
|
||||||
|
for f in /usr/lib/bashio/bashio.sh /usr/lib/bashio/lib.sh /usr/src/bashio/bashio.sh /usr/local/lib/bashio/bashio.sh; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
BASHIO_LIB="$f"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
if [ -z "$BASHIO_LIB" ]; then
|
||||||
|
for f in /usr/local/lib/bashio-standalone.sh /.bashio-standalone.sh; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
|
BASHIO_LIB="$f"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Starting scripts #
|
# Starting scripts #
|
||||||
####################
|
####################
|
||||||
@@ -193,7 +213,19 @@ run_one_script() {
|
|||||||
# shellcheck disable=SC1090
|
# shellcheck disable=SC1090
|
||||||
source "$script" || echo -e "\033[0;31mError\033[0m : $script exiting $?"
|
source "$script" || echo -e "\033[0;31mError\033[0m : $script exiting $?"
|
||||||
else
|
else
|
||||||
"$script" || echo -e "\033[0;31mError\033[0m : $script exiting $?"
|
_run_rc=0
|
||||||
|
"$script" || _run_rc=$?
|
||||||
|
if [ "$_run_rc" -eq 126 ] && [ -n "${BASHIO_LIB:-}" ]; then
|
||||||
|
echo "Direct exec failed (rc=126, likely E2BIG), retrying via source in subshell..."
|
||||||
|
(
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "$BASHIO_LIB" 2>/dev/null || true
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "$script"
|
||||||
|
) || echo -e "\033[0;31mError\033[0m : $script exiting $?"
|
||||||
|
elif [ "$_run_rc" -ne 0 ]; then
|
||||||
|
echo -e "\033[0;31mError\033[0m : $script exiting $_run_rc"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sed -i '1a exit 0' "$script"
|
sed -i '1a exit 0' "$script"
|
||||||
@@ -217,8 +249,19 @@ if $PID1; then
|
|||||||
restart_count=0
|
restart_count=0
|
||||||
max_restarts=5
|
max_restarts=5
|
||||||
while true; do
|
while true; do
|
||||||
"$runfile"
|
_svc_rc=0
|
||||||
rc=$?
|
"$runfile" || _svc_rc=$?
|
||||||
|
if [ "$_svc_rc" -eq 126 ] && [ -n "${BASHIO_LIB:-}" ]; then
|
||||||
|
echo "Direct exec of $runfile failed (rc=126, likely E2BIG), retrying via source..."
|
||||||
|
_svc_rc=0
|
||||||
|
(
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "$BASHIO_LIB" 2>/dev/null || true
|
||||||
|
# shellcheck disable=SC1090
|
||||||
|
. "$runfile"
|
||||||
|
) || _svc_rc=$?
|
||||||
|
fi
|
||||||
|
rc=$_svc_rc
|
||||||
if [ "$rc" -eq 0 ]; then
|
if [ "$rc" -eq 0 ]; then
|
||||||
echo "$runfile exited cleanly (exit 0), not restarting."
|
echo "$runfile exited cleanly (exit 0), not restarting."
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user