2024-07-11 13:37:35 +03:00
|
|
|
#!/bin/sh
|
|
|
|
set -f
|
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
[ -n "${IEP_TRACE}" ] || IEP_TRACE=0
|
|
|
|
[ "${IEP_TRACE}" = 1 ] || IEP_TRACE=0
|
|
|
|
[ "${IEP_TRACE}" = 0 ] || echo "# trace: $(date +'%Y-%m-%d %H:%M:%S.%03N %z'): start" >&2
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
iep_preserve_env() {
|
|
|
|
## preserve LD_PRELOAD
|
|
|
|
unset __IEP_LD_PRELOAD
|
|
|
|
__IEP_LD_PRELOAD="${LD_PRELOAD:-}"
|
|
|
|
unset LD_PRELOAD
|
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
## glibc: preserve GLIBC_TUNABLES
|
|
|
|
unset __IEP_GLIBC_TUNABLES
|
|
|
|
__IEP_GLIBC_TUNABLES="${GLIBC_TUNABLES:-}"
|
|
|
|
unset GLIBC_TUNABLES
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
## glibc: preserve MALLOC_ARENA_MAX
|
|
|
|
unset __IEP_MALLOC_ARENA_MAX
|
2024-07-23 00:03:46 +03:00
|
|
|
__IEP_MALLOC_ARENA_MAX="${MALLOC_ARENA_MAX:-2}"
|
2024-07-11 13:37:35 +03:00
|
|
|
export MALLOC_ARENA_MAX=2
|
2024-07-23 00:03:46 +03:00
|
|
|
|
|
|
|
## jemalloc: preserve MALLOC_CONF
|
|
|
|
unset __IEP_MALLOC_CONF
|
|
|
|
__IEP_MALLOC_CONF="${MALLOC_CONF:-}"
|
|
|
|
unset MALLOC_CONF
|
|
|
|
}
|
|
|
|
|
|
|
|
iep_prepare_env() {
|
|
|
|
## Angie: unset core variable
|
|
|
|
unset ANGIE ANGIE_BPF_MAPS
|
|
|
|
|
|
|
|
## dumb-init: preserve args
|
|
|
|
unset IEP_DUMB_INIT_ARGS
|
|
|
|
IEP_DUMB_INIT_ARGS="${DUMB_INIT_ARGS:-}"
|
|
|
|
unset DUMB_INIT_ARGS
|
|
|
|
if [ "${DUMB_INIT_SETSID:-}" = 0 ] ; then
|
|
|
|
IEP_DUMB_INIT_ARGS="-c${IEP_DUMB_INIT_ARGS:+ }${IEP_DUMB_INIT_ARGS}"
|
|
|
|
fi
|
|
|
|
unset DUMB_INIT_SETSID
|
2024-07-11 13:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
iep_restore_env() {
|
2024-07-23 00:03:46 +03:00
|
|
|
unset IEP_DEBUG IEP_VERBOSE IEP_TRACE IEP_ROOT
|
|
|
|
unset IEP_LOCAL_OVERRIDE IEP_RETAIN_MERGED_TREE IEP_RETAIN_ENV
|
2024-07-11 13:37:35 +03:00
|
|
|
|
|
|
|
## restore LD_PRELOAD
|
2024-07-23 00:03:46 +03:00
|
|
|
if [ -n "${__IEP_LD_PRELOAD:-}" ] ; then
|
2024-07-11 13:37:35 +03:00
|
|
|
export LD_PRELOAD="${__IEP_LD_PRELOAD}"
|
|
|
|
fi
|
|
|
|
unset __IEP_LD_PRELOAD
|
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
## glibc: restore GLIBC_TUNABLES
|
|
|
|
if [ -n "${__IEP_GLIBC_TUNABLES:-}" ] ; then
|
|
|
|
export GLIBC_TUNABLES="${__IEP_GLIBC_TUNABLES}"
|
|
|
|
fi
|
|
|
|
unset __IEP_GLIBC_TUNABLES
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
## glibc: restore MALLOC_ARENA_MAX
|
2024-07-23 00:03:46 +03:00
|
|
|
if [ -n "${__IEP_MALLOC_ARENA_MAX:-}" ] ; then
|
2024-07-11 13:37:35 +03:00
|
|
|
export MALLOC_ARENA_MAX="${__IEP_MALLOC_ARENA_MAX}"
|
|
|
|
fi
|
|
|
|
unset __IEP_MALLOC_ARENA_MAX
|
2024-07-23 00:03:46 +03:00
|
|
|
|
|
|
|
## jemalloc: restore MALLOC_CONF
|
|
|
|
if [ -n "${__IEP_MALLOC_CONF:-}" ] ; then
|
|
|
|
export MALLOC_CONF="${__IEP_MALLOC_CONF}"
|
|
|
|
fi
|
|
|
|
unset __IEP_MALLOC_CONF
|
2024-07-11 13:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
iep_preserve_env
|
2024-07-23 00:03:46 +03:00
|
|
|
iep_prepare_env
|
2024-07-11 13:37:35 +03:00
|
|
|
|
|
|
|
## early setup TMPDIR (affects "mktemp")
|
|
|
|
export TMPDIR=/run/angie/tmp
|
|
|
|
[ -d "${TMPDIR}" ] || install -d -m 03777 "${TMPDIR}"
|
|
|
|
|
|
|
|
## RFC: no need to run entire entrypoint for custom command
|
|
|
|
# case "$1" in
|
|
|
|
# angie | */angie ) ;;
|
|
|
|
# * )
|
|
|
|
# iep_restore_env
|
|
|
|
# exec "$@"
|
|
|
|
# ;;
|
|
|
|
# esac
|
|
|
|
|
|
|
|
unset __IEP_SRC ; __IEP_SRC="${0##*/}"
|
|
|
|
. /image-entry.d/00-common.envsh
|
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
IEP_INIT=$(gobool_to_int "${IEP_INIT:-0}" 0)
|
|
|
|
# unexport IEP_INIT
|
|
|
|
unset x ; x="${IEP_INIT}" ; unset IEP_INIT ; IEP_INIT="$x" ; unset x
|
|
|
|
|
|
|
|
IEP_RETAIN_MERGED_TREE=$(gobool_to_int "${IEP_RETAIN_MERGED_TREE:-0}" 0)
|
|
|
|
IEP_RETAIN_ENV=$(gobool_to_int "${IEP_RETAIN_ENV:-0}" 0)
|
|
|
|
export IEP_RETAIN_MERGED_TREE IEP_RETAIN_ENV
|
|
|
|
|
|
|
|
# IEP_TRACE=$(gobool_to_int "${IEP_TRACE:-0}" 0)
|
|
|
|
IEP_DEBUG=$(gobool_to_int "${IEP_DEBUG:-0}" 0)
|
|
|
|
IEP_VERBOSE=$(gobool_to_int "${IEP_VERBOSE:-${IEP_DEBUG}}" "${IEP_DEBUG}")
|
|
|
|
export IEP_TRACE IEP_DEBUG IEP_VERBOSE
|
2024-07-11 13:37:35 +03:00
|
|
|
|
|
|
|
## run parts (if any)
|
2024-07-23 00:03:46 +03:00
|
|
|
unset __IEP_SCRIPT
|
|
|
|
while read -r __IEP_SCRIPT ; do
|
|
|
|
[ -n "${__IEP_SCRIPT}" ] || continue
|
|
|
|
[ -f "${__IEP_SCRIPT}" ] || continue
|
2024-07-11 13:37:35 +03:00
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
|
|
|
|
case "${__IEP_SCRIPT}" in
|
2024-07-11 13:37:35 +03:00
|
|
|
*.envsh )
|
2024-07-23 00:03:46 +03:00
|
|
|
if ! [ -x "${__IEP_SCRIPT}" ] ; then
|
|
|
|
log "NOT sourcing ${__IEP_SCRIPT} - not executable"
|
2024-07-11 13:37:35 +03:00
|
|
|
continue
|
|
|
|
fi
|
2024-07-23 00:03:46 +03:00
|
|
|
[ "${IEP_TRACE}" = 0 ] || echo "# trace: $(date +'%Y-%m-%d %H:%M:%S.%03N %z'): source ${__IEP_SCRIPT}" >&2
|
|
|
|
log "sourcing ${__IEP_SCRIPT}"
|
|
|
|
__IEP_SRC="${__IEP_SCRIPT}"
|
|
|
|
. "${__IEP_SCRIPT}"
|
2024-07-11 13:37:35 +03:00
|
|
|
__IEP_SRC="${0##*/}"
|
|
|
|
;;
|
|
|
|
* )
|
2024-07-23 00:03:46 +03:00
|
|
|
if ! [ -x "${__IEP_SCRIPT}" ] ; then
|
|
|
|
log "NOT running ${__IEP_SCRIPT} - not executable"
|
2024-07-11 13:37:35 +03:00
|
|
|
continue
|
|
|
|
fi
|
2024-07-23 00:03:46 +03:00
|
|
|
[ "${IEP_TRACE}" = 0 ] || echo "# trace: $(date +'%Y-%m-%d %H:%M:%S.%03N %z'): run ${__IEP_SCRIPT}" >&2
|
|
|
|
log "running ${__IEP_SCRIPT}"
|
|
|
|
"${__IEP_SCRIPT}"
|
2024-07-11 13:37:35 +03:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done <<EOF
|
|
|
|
$(
|
|
|
|
if [ -d /image-entry ] ; then
|
|
|
|
overlay-dir-list.sh /image-entry.d /image-entry
|
|
|
|
else
|
|
|
|
find /image-entry.d/ -follow -type f | sort -V
|
|
|
|
fi
|
|
|
|
)
|
|
|
|
EOF
|
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
[ "${IEP_TRACE}" = 0 ] || echo "# trace: $(date +'%Y-%m-%d %H:%M:%S.%03N %z'): end" >&2
|
|
|
|
|
|
|
|
if [ "${IEP_DEBUG}" = 1 ] ; then
|
|
|
|
log_always "ready to run application: $*"
|
|
|
|
else
|
|
|
|
log_always "ready to run application"
|
|
|
|
fi
|
|
|
|
echo >&2
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
iep_restore_env
|
|
|
|
|
2024-07-23 00:03:46 +03:00
|
|
|
## variables that are not so easily unsettable
|
|
|
|
unset __IEP_ENV
|
|
|
|
for i in '_' 'SHLVL' ; do
|
|
|
|
__IEP_ENV="${__IEP_ENV:-}${__IEP_ENV:+ }-u $i"
|
|
|
|
done
|
|
|
|
|
2024-07-11 13:37:35 +03:00
|
|
|
if [ "${IEP_INIT}" = 0 ] ; then
|
2024-07-23 00:03:46 +03:00
|
|
|
exec \
|
|
|
|
${__IEP_ENV:+ env ${__IEP_ENV} } \
|
|
|
|
"$@"
|
2024-07-11 13:37:35 +03:00
|
|
|
else
|
2024-07-23 00:03:46 +03:00
|
|
|
exec \
|
|
|
|
${__IEP_ENV:+ env ${__IEP_ENV} } \
|
|
|
|
dumb-init ${IEP_DUMB_INIT_ARGS} \
|
|
|
|
"$@"
|
2024-07-11 13:37:35 +03:00
|
|
|
fi
|