167 lines
4.0 KiB
Bash
167 lines
4.0 KiB
Bash
|
#!/bin/sh
|
||
|
set -f
|
||
|
|
||
|
[ -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
|
||
|
|
||
|
iep_preserve_env() {
|
||
|
## preserve LD_PRELOAD
|
||
|
unset __IEP_LD_PRELOAD
|
||
|
__IEP_LD_PRELOAD="${LD_PRELOAD:-}"
|
||
|
unset LD_PRELOAD
|
||
|
|
||
|
## glibc: preserve GLIBC_TUNABLES
|
||
|
unset __IEP_GLIBC_TUNABLES
|
||
|
__IEP_GLIBC_TUNABLES="${GLIBC_TUNABLES:-}"
|
||
|
unset GLIBC_TUNABLES
|
||
|
|
||
|
## glibc: preserve MALLOC_ARENA_MAX
|
||
|
unset __IEP_MALLOC_ARENA_MAX
|
||
|
__IEP_MALLOC_ARENA_MAX="${MALLOC_ARENA_MAX:-2}"
|
||
|
export MALLOC_ARENA_MAX=2
|
||
|
|
||
|
## 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
|
||
|
}
|
||
|
|
||
|
iep_restore_env() {
|
||
|
unset IEP_DEBUG IEP_VERBOSE IEP_TRACE IEP_ROOT
|
||
|
unset IEP_LOCAL_OVERRIDE IEP_RETAIN_MERGED_TREE IEP_RETAIN_ENV
|
||
|
|
||
|
## restore LD_PRELOAD
|
||
|
if [ -n "${__IEP_LD_PRELOAD:-}" ] ; then
|
||
|
export LD_PRELOAD="${__IEP_LD_PRELOAD}"
|
||
|
fi
|
||
|
unset __IEP_LD_PRELOAD
|
||
|
|
||
|
## glibc: restore GLIBC_TUNABLES
|
||
|
if [ -n "${__IEP_GLIBC_TUNABLES:-}" ] ; then
|
||
|
export GLIBC_TUNABLES="${__IEP_GLIBC_TUNABLES}"
|
||
|
fi
|
||
|
unset __IEP_GLIBC_TUNABLES
|
||
|
|
||
|
## glibc: restore MALLOC_ARENA_MAX
|
||
|
if [ -n "${__IEP_MALLOC_ARENA_MAX:-}" ] ; then
|
||
|
export MALLOC_ARENA_MAX="${__IEP_MALLOC_ARENA_MAX}"
|
||
|
fi
|
||
|
unset __IEP_MALLOC_ARENA_MAX
|
||
|
|
||
|
## jemalloc: restore MALLOC_CONF
|
||
|
if [ -n "${__IEP_MALLOC_CONF:-}" ] ; then
|
||
|
export MALLOC_CONF="${__IEP_MALLOC_CONF}"
|
||
|
fi
|
||
|
unset __IEP_MALLOC_CONF
|
||
|
}
|
||
|
|
||
|
iep_preserve_env
|
||
|
iep_prepare_env
|
||
|
|
||
|
## 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
|
||
|
|
||
|
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_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
|
||
|
|
||
|
## run parts (if any)
|
||
|
unset __IEP_SCRIPT
|
||
|
while read -r __IEP_SCRIPT ; do
|
||
|
[ -n "${__IEP_SCRIPT}" ] || continue
|
||
|
[ -f "${__IEP_SCRIPT}" ] || continue
|
||
|
|
||
|
|
||
|
case "${__IEP_SCRIPT}" in
|
||
|
*.envsh )
|
||
|
if ! [ -x "${__IEP_SCRIPT}" ] ; then
|
||
|
log "NOT sourcing ${__IEP_SCRIPT} - not executable"
|
||
|
continue
|
||
|
fi
|
||
|
[ "${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}"
|
||
|
__IEP_SRC="${0##*/}"
|
||
|
;;
|
||
|
* )
|
||
|
if ! [ -x "${__IEP_SCRIPT}" ] ; then
|
||
|
log "NOT running ${__IEP_SCRIPT} - not executable"
|
||
|
continue
|
||
|
fi
|
||
|
[ "${IEP_TRACE}" = 0 ] || echo "# trace: $(date +'%Y-%m-%d %H:%M:%S.%03N %z'): run ${__IEP_SCRIPT}" >&2
|
||
|
log "running ${__IEP_SCRIPT}"
|
||
|
"${__IEP_SCRIPT}"
|
||
|
;;
|
||
|
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
|
||
|
|
||
|
[ "${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
|
||
|
|
||
|
iep_restore_env
|
||
|
|
||
|
## variables that are not so easily unsettable
|
||
|
unset __IEP_ENV
|
||
|
for i in '_' 'SHLVL' ; do
|
||
|
__IEP_ENV="${__IEP_ENV:-}${__IEP_ENV:+ }-u $i"
|
||
|
done
|
||
|
|
||
|
if [ "${IEP_INIT}" = 0 ] ; then
|
||
|
exec \
|
||
|
${__IEP_ENV:+ env ${__IEP_ENV} } \
|
||
|
"$@"
|
||
|
else
|
||
|
exec \
|
||
|
${__IEP_ENV:+ env ${__IEP_ENV} } \
|
||
|
dumb-init ${IEP_DUMB_INIT_ARGS} \
|
||
|
"$@"
|
||
|
fi
|