144 lines
3.2 KiB
Bash
Executable File
144 lines
3.2 KiB
Bash
Executable File
#!/bin/sh
|
|
set -f
|
|
|
|
. /run/ngx/iep/00-common.envsh
|
|
|
|
[ "${NGX_STRICT_LOAD}" = 0 ] || set -e
|
|
|
|
load_error_delim() {
|
|
IEP_DEBUG=0 log_always ' ----------------------------------- '
|
|
}
|
|
unset load_error_seen
|
|
load_error() {
|
|
[ "${load_error_seen:-}" != 1 ] || return
|
|
load_error_seen=1
|
|
load_error_delim
|
|
log_always 'tree combine has failed'
|
|
if [ "${NGX_STRICT_LOAD}" = 1 ] ; then
|
|
t=15
|
|
log_always "injecting delay for $t seconds"
|
|
load_error_delim
|
|
sleep $t
|
|
exit 1
|
|
fi
|
|
load_error_delim
|
|
}
|
|
|
|
install -d "${volume_root}/conf.load"
|
|
|
|
## Angie modules are loaded in [strict] order!
|
|
combine_modules() {
|
|
[ -n "$1" ] || return 1
|
|
local n
|
|
n="$1" ; shift
|
|
|
|
[ $# -ne 0 ] || return 0
|
|
|
|
local i m src_dir dst_dir src_name dst_name src_path dst_path dst_dir
|
|
src_dir="${target_root}/mod"
|
|
dst_dir="${volume_root}/conf.load"
|
|
|
|
i=0
|
|
for m ; do
|
|
[ -n "$m" ] || continue
|
|
|
|
case "$m" in
|
|
/* | */../* | *\** | *\?* )
|
|
log_always "module config filename '$m' is not legal, skipping"
|
|
continue
|
|
;;
|
|
esac
|
|
|
|
case "$m" in
|
|
*/* ) src_name="$m.conf" ;;
|
|
* ) src_name="$n-$m.conf" ;;
|
|
esac
|
|
dst_name=$(printf 'mod-%s-%02d-%s.conf' "$n" "$i" "$m" | tr -s '/_' '_')
|
|
|
|
src_path="${src_dir}/${src_name}"
|
|
if ! [ -f "${src_path}" ] ; then
|
|
log_always "file ${src_name} is not found in ${src_dir}/"
|
|
load_error
|
|
log "file ${src_name} is skipped"
|
|
continue
|
|
fi
|
|
|
|
dst_path="${dst_dir}/${dst_name}"
|
|
|
|
ln_cp "${src_path}" "${dst_path}"
|
|
|
|
i=$((i+1))
|
|
done
|
|
}
|
|
|
|
combine_confload() {
|
|
[ -n "$1" ] || return 1
|
|
local n
|
|
n="$1" ; shift
|
|
|
|
[ $# -ne 0 ] || return 0
|
|
|
|
local s src_dir dst_dir src_name dst_name src_path dst_path
|
|
src_dir="${target_root}/conf"
|
|
dst_dir="${volume_root}/conf.load"
|
|
|
|
for s ; do
|
|
[ -n "$s" ] || continue
|
|
|
|
case "$s" in
|
|
/* | */../* | *\** | *\?* )
|
|
log_always "config filename '$s' is not legal, skipping"
|
|
continue
|
|
;;
|
|
esac
|
|
|
|
case "$s" in
|
|
*/* ) src_name="$s.conf" ;;
|
|
* ) src_name="$n-$s.conf" ;;
|
|
esac
|
|
dst_name=$(printf '%s-%s.conf' "$n" "$s" | tr -s '/_' '_')
|
|
|
|
dst_path="${dst_dir}/${dst_name}"
|
|
if [ -e "${dst_path}" ] ; then
|
|
log "${dst_path} already exists, skipping"
|
|
continue
|
|
fi
|
|
|
|
src_path="${src_dir}/${src_name}"
|
|
if ! [ -f "${src_path}" ] ; then
|
|
log_always "file ${src_name} is not found in ${src_dir}/"
|
|
if [ "${NGX_ALLOW_MISSING_CONFLOAD:-}" != 1 ] ; then
|
|
load_error
|
|
log "file ${src_name} is skipped"
|
|
fi
|
|
continue
|
|
fi
|
|
|
|
ln_cp "${src_path}" "${dst_path}"
|
|
done
|
|
}
|
|
|
|
combine_modules core ${NGX_CORE_MODULES:-}
|
|
combine_modules http ${NGX_HTTP_MODULES:-}
|
|
combine_modules mail ${NGX_MAIL_MODULES:-}
|
|
combine_modules stream ${NGX_STREAM_MODULES:-}
|
|
|
|
loose=$(( 1 - NGX_STRICT_LOAD ))
|
|
NGX_ALLOW_MISSING_CONFLOAD=$(gobool_to_int "${NGX_ALLOW_MISSING_CONFLOAD:-${loose}}" ${loose})
|
|
|
|
combine_confload core ${NGX_CORE_CONFLOAD:-}
|
|
combine_confload core_ev ${NGX_CORE_EVENTS_CONFLOAD:-}
|
|
combine_confload http ${NGX_HTTP_CONFLOAD:-}
|
|
combine_confload mail ${NGX_MAIL_CONFLOAD:-}
|
|
combine_confload stream ${NGX_STREAM_CONFLOAD:-}
|
|
|
|
## some modules doesn't have configuration at all
|
|
NGX_ALLOW_MISSING_CONFLOAD=1
|
|
|
|
combine_confload core ${NGX_CORE_MODULES:-}
|
|
combine_confload http ${NGX_HTTP_MODULES:-}
|
|
combine_confload mail ${NGX_MAIL_MODULES:-}
|
|
combine_confload stream ${NGX_STREAM_MODULES:-}
|
|
|
|
exit 0
|