Skip to content

Commit c03e750

Browse files
committed
Multiple updates
* Don't close FD 3 (it might be an inherited activate socket) * Implement workaround for cgroups2 * Improve ENV variables handling
1 parent 85ac2dd commit c03e750

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+420
-288
lines changed

entrypoint/10-listen-on-ipv6-by-default.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,65 @@
33

44
set -e
55

6+
entrypoint_log() {
7+
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
8+
echo "$@"
9+
fi
10+
}
11+
612
ME=$(basename $0)
713
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
814

915
# check if we have ipv6 available
1016
if [ ! -f "/proc/net/if_inet6" ]; then
11-
echo >&3 "$ME: info: ipv6 not available"
17+
entrypoint_log "$ME: info: ipv6 not available"
1218
exit 0
1319
fi
1420

1521
if [ ! -f "/$DEFAULT_CONF_FILE" ]; then
16-
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE is not a file or does not exist"
22+
entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE is not a file or does not exist"
1723
exit 0
1824
fi
1925

2026
# check if the file can be modified, e.g. not on a r/o filesystem
21-
touch /$DEFAULT_CONF_FILE 2>/dev/null || { echo >&3 "$ME: info: can not modify /$DEFAULT_CONF_FILE (read-only file system?)"; exit 0; }
27+
touch /$DEFAULT_CONF_FILE 2>/dev/null || { entrypoint_log "$ME: info: can not modify /$DEFAULT_CONF_FILE (read-only file system?)"; exit 0; }
2228

2329
# check if the file is already modified, e.g. on a container restart
24-
grep -q "listen \[::]\:8080;" /$DEFAULT_CONF_FILE && { echo >&3 "$ME: info: IPv6 listen already enabled"; exit 0; }
30+
grep -q "listen \[::]\:8080;" /$DEFAULT_CONF_FILE && { entrypoint_log "$ME: info: IPv6 listen already enabled"; exit 0; }
2531

2632
if [ -f "/etc/os-release" ]; then
2733
. /etc/os-release
2834
else
29-
echo >&3 "$ME: info: can not guess the operating system"
35+
entrypoint_log "$ME: info: can not guess the operating system"
3036
exit 0
3137
fi
3238

33-
echo >&3 "$ME: info: Getting the checksum of /$DEFAULT_CONF_FILE"
39+
entrypoint_log "$ME: info: Getting the checksum of /$DEFAULT_CONF_FILE"
3440

3541
case "$ID" in
3642
"debian")
3743
CHECKSUM=$(dpkg-query --show --showformat='${Conffiles}\n' nginx | grep $DEFAULT_CONF_FILE | cut -d' ' -f 3)
3844
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | md5sum -c - >/dev/null 2>&1 || {
39-
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
45+
entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
4046
exit 0
4147
}
4248
;;
4349
"alpine")
4450
CHECKSUM=$(apk manifest nginx 2>/dev/null| grep $DEFAULT_CONF_FILE | cut -d' ' -f 1 | cut -d ':' -f 2)
4551
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | sha1sum -c - >/dev/null 2>&1 || {
46-
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
52+
entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
4753
exit 0
4854
}
4955
;;
5056
*)
51-
echo >&3 "$ME: info: Unsupported distribution"
57+
entrypoint_log "$ME: info: Unsupported distribution"
5258
exit 0
5359
;;
5460
esac
5561

5662
# enable ipv6 on default.conf listen sockets
5763
sed -i -E 's,listen 8080;,listen 8080;\n listen [::]:8080;,' /$DEFAULT_CONF_FILE
5864

59-
echo >&3 "$ME: info: Enabled listen on IPv6 in /$DEFAULT_CONF_FILE"
65+
entrypoint_log "$ME: info: Enabled listen on IPv6 in /$DEFAULT_CONF_FILE"
6066

6167
exit 0

entrypoint/20-envsubst-on-templates.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ set -e
44

55
ME=$(basename $0)
66

7+
entrypoint_log() {
8+
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
9+
echo "$@"
10+
fi
11+
}
12+
713
auto_envsubst() {
814
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
915
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1016
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
1117

1218
local template defined_envs relative_path output_path subdir
13-
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
19+
defined_envs=$(printf '${%s} ' $(xargs -0n1 -a /proc/self/environ sh -c 'echo "$@" | grep -oEm1 "^[^=]+"' --));
1420
[ -d "$template_dir" ] || return 0
1521
if [ ! -w "$output_dir" ]; then
16-
echo >&3 "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
22+
entrypoint_log "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
1723
return 0
1824
fi
1925
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
@@ -22,7 +28,7 @@ auto_envsubst() {
2228
subdir=$(dirname "$relative_path")
2329
# create a subdirectory where the template file exists
2430
mkdir -p "$output_dir/$subdir"
25-
echo >&3 "$ME: Running envsubst on $template to $output_path"
31+
entrypoint_log "$ME: Running envsubst on $template to $output_path"
2632
envsubst "$defined_envs" < "$template" > "$output_path"
2733
done
2834
}

entrypoint/30-tune-worker-processes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ __EOF__
158158
"/")
159159
foundroot="${found##* }$mountpoint"
160160
;;
161-
"$mountpoint")
161+
"$mountpoint" | /../*)
162162
foundroot="${found##* }"
163163
;;
164164
esac

entrypoint/docker-entrypoint.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33

44
set -e
55

6-
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
7-
exec 3>&1
8-
else
9-
exec 3>/dev/null
10-
fi
6+
entrypoint_log() {
7+
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
8+
echo "$@"
9+
fi
10+
}
1111

1212
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
1313
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
14-
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
14+
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
1515

16-
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
16+
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
1717
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
1818
case "$f" in
1919
*.sh)
2020
if [ -x "$f" ]; then
21-
echo >&3 "$0: Launching $f";
21+
entrypoint_log "$0: Launching $f";
2222
"$f"
2323
else
2424
# warn on shell scripts without exec bit
25-
echo >&3 "$0: Ignoring $f, not executable";
25+
entrypoint_log "$0: Ignoring $f, not executable";
2626
fi
2727
;;
28-
*) echo >&3 "$0: Ignoring $f";;
28+
*) entrypoint_log "$0: Ignoring $f";;
2929
esac
3030
done
3131

32-
echo >&3 "$0: Configuration complete; ready for start up"
32+
entrypoint_log "$0: Configuration complete; ready for start up"
3333
else
34-
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
34+
entrypoint_log "$0: No files found in /docker-entrypoint.d/, skipping configuration"
3535
fi
3636
fi
3737

mainline/alpine-perl/10-listen-on-ipv6-by-default.sh

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,59 +3,65 @@
33

44
set -e
55

6+
entrypoint_log() {
7+
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
8+
echo "$@"
9+
fi
10+
}
11+
612
ME=$(basename $0)
713
DEFAULT_CONF_FILE="etc/nginx/conf.d/default.conf"
814

915
# check if we have ipv6 available
1016
if [ ! -f "/proc/net/if_inet6" ]; then
11-
echo >&3 "$ME: info: ipv6 not available"
17+
entrypoint_log "$ME: info: ipv6 not available"
1218
exit 0
1319
fi
1420

1521
if [ ! -f "/$DEFAULT_CONF_FILE" ]; then
16-
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE is not a file or does not exist"
22+
entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE is not a file or does not exist"
1723
exit 0
1824
fi
1925

2026
# check if the file can be modified, e.g. not on a r/o filesystem
21-
touch /$DEFAULT_CONF_FILE 2>/dev/null || { echo >&3 "$ME: info: can not modify /$DEFAULT_CONF_FILE (read-only file system?)"; exit 0; }
27+
touch /$DEFAULT_CONF_FILE 2>/dev/null || { entrypoint_log "$ME: info: can not modify /$DEFAULT_CONF_FILE (read-only file system?)"; exit 0; }
2228

2329
# check if the file is already modified, e.g. on a container restart
24-
grep -q "listen \[::]\:8080;" /$DEFAULT_CONF_FILE && { echo >&3 "$ME: info: IPv6 listen already enabled"; exit 0; }
30+
grep -q "listen \[::]\:8080;" /$DEFAULT_CONF_FILE && { entrypoint_log "$ME: info: IPv6 listen already enabled"; exit 0; }
2531

2632
if [ -f "/etc/os-release" ]; then
2733
. /etc/os-release
2834
else
29-
echo >&3 "$ME: info: can not guess the operating system"
35+
entrypoint_log "$ME: info: can not guess the operating system"
3036
exit 0
3137
fi
3238

33-
echo >&3 "$ME: info: Getting the checksum of /$DEFAULT_CONF_FILE"
39+
entrypoint_log "$ME: info: Getting the checksum of /$DEFAULT_CONF_FILE"
3440

3541
case "$ID" in
3642
"debian")
3743
CHECKSUM=$(dpkg-query --show --showformat='${Conffiles}\n' nginx | grep $DEFAULT_CONF_FILE | cut -d' ' -f 3)
3844
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | md5sum -c - >/dev/null 2>&1 || {
39-
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
45+
entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
4046
exit 0
4147
}
4248
;;
4349
"alpine")
4450
CHECKSUM=$(apk manifest nginx 2>/dev/null| grep $DEFAULT_CONF_FILE | cut -d' ' -f 1 | cut -d ':' -f 2)
4551
echo "$CHECKSUM /$DEFAULT_CONF_FILE" | sha1sum -c - >/dev/null 2>&1 || {
46-
echo >&3 "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
52+
entrypoint_log "$ME: info: /$DEFAULT_CONF_FILE differs from the packaged version"
4753
exit 0
4854
}
4955
;;
5056
*)
51-
echo >&3 "$ME: info: Unsupported distribution"
57+
entrypoint_log "$ME: info: Unsupported distribution"
5258
exit 0
5359
;;
5460
esac
5561

5662
# enable ipv6 on default.conf listen sockets
5763
sed -i -E 's,listen 8080;,listen 8080;\n listen [::]:8080;,' /$DEFAULT_CONF_FILE
5864

59-
echo >&3 "$ME: info: Enabled listen on IPv6 in /$DEFAULT_CONF_FILE"
65+
entrypoint_log "$ME: info: Enabled listen on IPv6 in /$DEFAULT_CONF_FILE"
6066

6167
exit 0

mainline/alpine-perl/20-envsubst-on-templates.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,22 @@ set -e
44

55
ME=$(basename $0)
66

7+
entrypoint_log() {
8+
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
9+
echo "$@"
10+
fi
11+
}
12+
713
auto_envsubst() {
814
local template_dir="${NGINX_ENVSUBST_TEMPLATE_DIR:-/etc/nginx/templates}"
915
local suffix="${NGINX_ENVSUBST_TEMPLATE_SUFFIX:-.template}"
1016
local output_dir="${NGINX_ENVSUBST_OUTPUT_DIR:-/etc/nginx/conf.d}"
1117

1218
local template defined_envs relative_path output_path subdir
13-
defined_envs=$(printf '${%s} ' $(env | cut -d= -f1))
19+
defined_envs=$(printf '${%s} ' $(xargs -0n1 -a /proc/self/environ sh -c 'echo "$@" | grep -oEm1 "^[^=]+"' --));
1420
[ -d "$template_dir" ] || return 0
1521
if [ ! -w "$output_dir" ]; then
16-
echo >&3 "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
22+
entrypoint_log "$ME: ERROR: $template_dir exists, but $output_dir is not writable"
1723
return 0
1824
fi
1925
find "$template_dir" -follow -type f -name "*$suffix" -print | while read -r template; do
@@ -22,7 +28,7 @@ auto_envsubst() {
2228
subdir=$(dirname "$relative_path")
2329
# create a subdirectory where the template file exists
2430
mkdir -p "$output_dir/$subdir"
25-
echo >&3 "$ME: Running envsubst on $template to $output_path"
31+
entrypoint_log "$ME: Running envsubst on $template to $output_path"
2632
envsubst "$defined_envs" < "$template" > "$output_path"
2733
done
2834
}

mainline/alpine-perl/30-tune-worker-processes.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ __EOF__
158158
"/")
159159
foundroot="${found##* }$mountpoint"
160160
;;
161-
"$mountpoint")
161+
"$mountpoint" | /../*)
162162
foundroot="${found##* }"
163163
;;
164164
esac

mainline/alpine-perl/docker-entrypoint.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@
33

44
set -e
55

6-
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
7-
exec 3>&1
8-
else
9-
exec 3>/dev/null
10-
fi
6+
entrypoint_log() {
7+
if [ -z "${NGINX_ENTRYPOINT_QUIET_LOGS:-}" ]; then
8+
echo "$@"
9+
fi
10+
}
1111

1212
if [ "$1" = "nginx" -o "$1" = "nginx-debug" ]; then
1313
if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -maxdepth 1 -type f -print -quit 2>/dev/null | read v; then
14-
echo >&3 "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
14+
entrypoint_log "$0: /docker-entrypoint.d/ is not empty, will attempt to perform configuration"
1515

16-
echo >&3 "$0: Looking for shell scripts in /docker-entrypoint.d/"
16+
entrypoint_log "$0: Looking for shell scripts in /docker-entrypoint.d/"
1717
find "/docker-entrypoint.d/" -follow -type f -print | sort -V | while read -r f; do
1818
case "$f" in
1919
*.sh)
2020
if [ -x "$f" ]; then
21-
echo >&3 "$0: Launching $f";
21+
entrypoint_log "$0: Launching $f";
2222
"$f"
2323
else
2424
# warn on shell scripts without exec bit
25-
echo >&3 "$0: Ignoring $f, not executable";
25+
entrypoint_log "$0: Ignoring $f, not executable";
2626
fi
2727
;;
28-
*) echo >&3 "$0: Ignoring $f";;
28+
*) entrypoint_log "$0: Ignoring $f";;
2929
esac
3030
done
3131

32-
echo >&3 "$0: Configuration complete; ready for start up"
32+
entrypoint_log "$0: Configuration complete; ready for start up"
3333
else
34-
echo >&3 "$0: No files found in /docker-entrypoint.d/, skipping configuration"
34+
entrypoint_log "$0: No files found in /docker-entrypoint.d/, skipping configuration"
3535
fi
3636
fi
3737

0 commit comments

Comments
 (0)