forked from mapfish/mapfish-print
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-start-print
More file actions
executable file
·99 lines (81 loc) · 3.54 KB
/
Copy pathdocker-start-print
File metadata and controls
executable file
·99 lines (81 loc) · 3.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash -e
export JAVA_OPTS="--add-opens=java.desktop/sun.awt.image=ALL-UNNAMED ${JAVA_OPTS}"
normalize_context_path() {
local raw="${1:-}"
if [[ -z "${raw}" || "${raw}" == "/" ]]; then
echo ""
return 0
fi
if [[ "${raw}" != /* ]]; then
raw="/${raw}"
fi
# Remove trailing slashes (keep the leading slash)
while [[ "${raw}" != "/" && "${raw}" == */ ]]; do
raw="${raw%/}"
done
# Conservative validation: allow common URL path chars
if [[ ! "${raw}" =~ ^/[A-Za-z0-9._/-]+$ ]]; then
echo "ERROR: Invalid CONTEXT_PATH: '${1}'. Expected like '/print' or '/foo/bar'." >&2
exit 2
fi
echo "${raw}"
}
apply_context_path() {
local context_path="${1}"
if [[ -z "${context_path}" ]]; then
return 0
fi
echo "Configuring CONTEXT_PATH='${context_path}'"
local web_xml="WEB-INF/web.xml"
if [[ ! -w "${web_xml}" ]]; then
echo "ERROR: CONTEXT_PATH is set but '${web_xml}' is not writable." >&2
echo " If you run with a read-only root filesystem, mount a writable volume over" >&2
echo " /usr/local/tomcat/webapps/ROOT (or at least WEB-INF and the context-path folder)." >&2
exit 1
fi
# Prefix servlet url-patterns. This makes deployments behind a reverse proxy under a sub path
# (where the proxy does NOT strip the prefix) work out of the box.
# Idempotent: only rewrites the original patterns.
sed -i \
-e "s|<url-pattern>/metrics</url-pattern>|<url-pattern>${context_path}/metrics</url-pattern>|g" \
-e "s|<url-pattern>/metrics/\*</url-pattern>|<url-pattern>${context_path}/metrics/*</url-pattern>|g" \
-e "s|<url-pattern>/print/\*</url-pattern>|<url-pattern>${context_path}/print/*</url-pattern>|g" \
-e "s|<url-pattern>/sec/print/\*</url-pattern>|<url-pattern>${context_path}/sec/print/*</url-pattern>|g" \
"${web_xml}"
# Make the UI reachable under the context path by copying the static files.
# Example: CONTEXT_PATH=/print -> /usr/local/tomcat/webapps/ROOT/print/index.html
local ui_dir=".${context_path}"
mkdir -p "${ui_dir}"
for f in index.html favicon.ico mapfish_transparent.png; do
if [[ -f "${f}" ]]; then
cp -f "${f}" "${ui_dir}/"
fi
done
if [[ -w "${ui_dir}/index.html" ]]; then
# Ensure exactly one <base> tag, so relative links resolve via the external prefix.
sed -i '/<base[[:space:]]\+href=/d' "${ui_dir}/index.html"
sed -i "/<\/head>/i\\ <base href=\"${context_path}/\" />" "${ui_dir}/index.html"
else
echo "WARNING: Unable to update '${ui_dir}/index.html' to set <base href>." >&2
fi
}
cd /usr/local/tomcat/webapps/ROOT
CONTEXT_PATH_NORMALIZED="$(normalize_context_path "${CONTEXT_PATH:-}")"
apply_context_path "${CONTEXT_PATH_NORMALIZED}"
PG_LIB=$(find WEB-INF/lib -name "postgresql-*")
# Checks if Database is present (DB is compulsory in cluster mode)
if java ${CATALINA_OPTS} -cp WEB-INF/classes/:$PG_LIB org.mapfish.print.WaitDB; then
cp WEB-INF/classes/mapfish-spring-application-context-override-db.xml \
WEB-INF/classes/mapfish-spring-application-context-override.xml
fi
if [[ -n "${EXTRA_JARS}" ]]; then
while [[ ! -d "${EXTRA_JARS}" ]]; do
echo "Waiting for ${EXTRA_JARS} to be present"
sleep 1
done
echo "Adding jar files:"
cp -v "${EXTRA_JARS}"/*.jar WEB-INF/lib/
fi
mkdir -p print-apps
rm -f /usr/local/tomcat/temp/mapfish-print/ROOT/stop /usr/local/tomcat/temp/mapfish-print/ROOT/stopped
exec catalina.sh run