186 lines
4.0 KiB
Bash
Executable File
186 lines
4.0 KiB
Bash
Executable File
#!/bin/sh
|
|
set -f
|
|
|
|
. /image-entry.d/00-common.envsh
|
|
|
|
[ "${NGX_STRICT_LOAD}" = 0 ] || set -e
|
|
|
|
load_error() {
|
|
[ "${load_error_seen:-}" = 1 ] || log_always 'tree combine has failed'
|
|
load_error_seen=1
|
|
if [ "${NGX_STRICT_LOAD}" = 1 ] ; then
|
|
t=10
|
|
log_always "injecting delay for $t seconds"
|
|
sleep $t
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
smart_ln() {
|
|
if [ -h "$1" ] ; then
|
|
ln_s "$(readlink -e "$1")" "$2"
|
|
else
|
|
cp "$1" "$2"
|
|
fi
|
|
}
|
|
|
|
dirs='conf modules njs site'
|
|
[ "${NGX_PROCESS_STATIC}" = 0 ] || dirs="${dirs} static"
|
|
while read -r old_path ; do
|
|
[ -n "${old_path}" ] || continue
|
|
|
|
new_path=$(combine_remap_path "${old_path}")
|
|
[ -n "${new_path}" ]
|
|
|
|
new_dir="${new_path%/*}"
|
|
[ -d "${new_dir}" ] || mkdir -p "${new_dir}"
|
|
|
|
smart_ln "${old_path}" "${new_path}"
|
|
done <<-EOF
|
|
$(
|
|
for n in ${dirs} ; do
|
|
[ -d "${merged_root}/$n" ] || continue
|
|
find "${merged_root}/$n/" ! -type d
|
|
done | sort -V
|
|
)
|
|
EOF
|
|
|
|
if [ "${NGX_PROCESS_STATIC}" = 0 ] ; then
|
|
for d in /angie/static /etc/angie/static /etc/angie/static.dist ; do
|
|
[ -d "$d" ] || continue
|
|
ln_s "$d" /run/angie/static
|
|
break
|
|
done
|
|
fi
|
|
|
|
dirs='cache lib log'
|
|
for n in ${dirs} ; do
|
|
s="/angie/$n"
|
|
d="/run/angie/$n"
|
|
|
|
if [ -d "$s" ] ; then
|
|
ln_s "$s" "$d"
|
|
else
|
|
[ -d "$d" ] || install_userdir "$d"
|
|
fi
|
|
done
|
|
|
|
## provide same symlinks as upstream (both Angie and nginx) docker images do
|
|
d=/run/angie/log
|
|
[ -e "$d/access.log" ] || ln_s /dev/stdout "$d/access.log"
|
|
[ -e "$d/error.log" ] || ln_s /dev/stderr "$d/error.log"
|
|
|
|
## Angie modules are loaded in [strict] order!
|
|
combine_modules() {
|
|
[ -n "$1" ] || return 1
|
|
n="$1" ; shift
|
|
|
|
i=0
|
|
for m ; do
|
|
[ -n "$m" ] || continue
|
|
|
|
old_name="mod/$n-$m.conf"
|
|
|
|
old_path="${merged_root}/${old_name}"
|
|
if ! [ -f "${old_path}" ] ; then
|
|
log_always "file ${old_name} is not found"
|
|
load_error
|
|
log "file ${old_name} is skipped"
|
|
continue
|
|
fi
|
|
|
|
new_path=$(printf "/run/angie/mod/$n-%02d-%s.conf" "$i" "$m")
|
|
new_dir="${new_path%/*}"
|
|
[ -d "${new_dir}" ] || mkdir -p "${new_dir}"
|
|
|
|
smart_ln "${old_path}" "${new_path}"
|
|
|
|
i=$((i+1))
|
|
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:-}
|
|
|
|
combine_snippets() {
|
|
[ -n "$1" ] || return 1
|
|
n="$1" ; shift
|
|
|
|
for s ; do
|
|
[ -n "$s" ] || continue
|
|
|
|
old_name="snip/$n-$s.conf"
|
|
|
|
old_path="${merged_root}/${old_name}"
|
|
if ! [ -f "${old_path}" ] ; then
|
|
log_always "file ${old_name} is not found"
|
|
load_error
|
|
log "file ${old_name} is skipped"
|
|
continue
|
|
fi
|
|
|
|
new_path="/run/angie/${old_name}"
|
|
new_dir="${new_path%/*}"
|
|
[ -d "${new_dir}" ] || mkdir -p "${new_dir}"
|
|
|
|
smart_ln "${old_path}" "${new_path}"
|
|
done
|
|
}
|
|
|
|
combine_snippets core ${NGX_CORE_SNIPPETS:-}
|
|
combine_snippets core_ev ${NGX_CORE_EVENTS_SNIPPETS:-}
|
|
combine_snippets http ${NGX_HTTP_SNIPPETS:-}
|
|
combine_snippets mail ${NGX_MAIL_SNIPPETS:-}
|
|
combine_snippets stream ${NGX_STREAM_SNIPPETS:-}
|
|
|
|
combine_module_snippets() {
|
|
[ -n "$1" ] || return 1
|
|
n="$1" ; shift
|
|
|
|
for s ; do
|
|
[ -n "$s" ] || continue
|
|
|
|
old_name="snip/$n-$s.conf"
|
|
|
|
old_path="${merged_root}/${old_name}"
|
|
if ! [ -f "${old_path}" ] ; then
|
|
log "file ${old_name} is not found, skipping"
|
|
continue
|
|
fi
|
|
|
|
new_path="/run/angie/${old_name}"
|
|
new_dir="${new_path%/*}"
|
|
[ -d "${new_dir}" ] || mkdir -p "${new_dir}"
|
|
|
|
smart_ln "${old_path}" "${new_path}"
|
|
done
|
|
}
|
|
|
|
combine_module_snippets core ${NGX_CORE_MODULES:-}
|
|
combine_module_snippets http ${NGX_HTTP_MODULES:-}
|
|
combine_module_snippets mail ${NGX_MAIL_MODULES:-}
|
|
combine_module_snippets stream ${NGX_STREAM_MODULES:-}
|
|
|
|
## merge remaining snippets
|
|
while read -r old_path ; do
|
|
[ -n "${old_path}" ] || continue
|
|
|
|
new_path=$(combine_remap_path "${old_path}")
|
|
[ -n "${new_path}" ] || exit 1
|
|
|
|
new_dir="${new_path%/*}"
|
|
[ -d "${new_dir}" ] || mkdir -p "${new_dir}"
|
|
|
|
smart_ln "${old_path}" "${new_path}"
|
|
done <<-EOF
|
|
$(
|
|
find "${merged_root}/snip/" ! -type d \
|
|
| grep -Ev -e "^${merged_root}/snip/(core|core_ev|http|mail|stream)-[^/]*\.conf\$" \
|
|
| sort -V
|
|
)
|
|
EOF
|
|
|
|
exit 0
|