forked from teamatldocker/confluence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-entrypoint.sh
executable file
·265 lines (233 loc) · 10.1 KB
/
docker-entrypoint.sh
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/bin/bash
#
# A helper script for ENTRYPOINT.
#
# If first CMD argument is 'confluence', then the script will bootstrap Confluence
# If CMD argument is overriden and not 'confluence', then the user wants to run
# his own process.
set -o errexit
[[ ${DEBUG} == true ]] && set -x
SERAPH_CONFIG_FILE="/opt/atlassian/confluence/confluence/WEB-INF/classes/seraph-config.xml"
CROWD_PROPERTIES_FILE="/opt/atlassian/confluence/confluence/WEB-INF/classes/crowd.properties"
function updateProperties() {
local propertyfile=$1
local propertyname=$2
local propertyvalue=$3
sed -i "/${propertyname}/d" ${propertyfile}
echo "${propertyname}=${propertyvalue}" >> ${propertyfile}
}
#
# Enable crowd sso authenticator java class in image config file
#
function enableCrowdSSO() {
xmlstarlet ed -P -S -L --delete "//authenticator" $SERAPH_CONFIG_FILE
xmlstarlet ed -P -S -L -s "//security-config" --type elem -n authenticator -i "//authenticator[not(@class)]" -t attr -n class -v "com.atlassian.confluence.user.ConfluenceCrowdSSOAuthenticator" $SERAPH_CONFIG_FILE
if [ -f "${CROWD_PROPERTIES_FILE}" ]; then
rm -f ${CROWD_PROPERTIES_FILE}
touch ${CROWD_PROPERTIES_FILE}
fi
if [ -n "${CROWD_SSO_APPLICATION_NAME}" ]; then
updateProperties ${CROWD_PROPERTIES_FILE} "application.name" "${CROWD_SSO_APPLICATION_NAME}"
fi
if [ -n "${CROWD_SSO_APPLICATION_PASSWORD}" ]; then
updateProperties ${CROWD_PROPERTIES_FILE} "application.password" "${CROWD_SSO_APPLICATION_PASSWORD}"
fi
if [ -n "${CROWD_SSO_BASE_URL}" ]; then
updateProperties ${CROWD_PROPERTIES_FILE} "crowd.base.url" "${CROWD_SSO_BASE_URL}"
updateProperties ${CROWD_PROPERTIES_FILE} "crowd.server.url" "${CROWD_SSO_BASE_URL}services/"
fi
if [ -n "${CROWD_SSO_SESSION_VALIDATION}" ]; then
updateProperties ${CROWD_PROPERTIES_FILE} "session.validationinterval" ${CROWD_SSO_SESSION_VALIDATION}
else
updateProperties ${CROWD_PROPERTIES_FILE} "session.validationinterval" "2"
fi
echo 'application.login.url
session.isauthenticated=session.isauthenticated
session.tokenkey=session.tokenkey
session.lastvalidation=session.lastvalidation
' >> ${CROWD_PROPERTIES_FILE}
}
#
# Enable confluence authenticator java class in image config file
#
function enableConfluenceAuth() {
xmlstarlet ed -P -S -L --delete "//authenticator" $SERAPH_CONFIG_FILE
xmlstarlet ed -P -S -L -s "//security-config" --type elem -n authenticator -i "//authenticator[not(@class)]" -t attr -n class -v "com.atlassian.confluence.user.ConfluenceAuthenticator" $SERAPH_CONFIG_FILE
}
#
# Will either enable, disable Crowd SSO support or ignore current setting at all
#
function controlCrowdSSO() {
local setting=$1
case "$setting" in
true)
enableCrowdSSO
;;
false)
enableConfluenceAuth
;;
*)
echo "Crowd SSO settings ingored because of setting ${setting}"
esac
}
function createConfluenceTempDirectory() {
CONFLUENCE_CATALINA_TMPDIR=${CONF_HOME}/temp
if [ -n "${CATALINA_TMPDIR}" ]; then
CONFLUENCE_CATALINA_TMPDIR=$CATALINA_TMPDIR
fi
if [ ! -d "${CONFLUENCE_CATALINA_TMPDIR}" ]; then
mkdir -p ${CONFLUENCE_CATALINA_TMPDIR}
export CATALINA_TMPDIR="$CONFLUENCE_CATALINA_TMPDIR"
fi
}
function processConfluenceLogfileSettings() {
if [ -n "${CONFLUENCE_LOGFILE_LOCATION}" ]; then
confluence_logfile=${CONFLUENCE_LOGFILE_LOCATION}
fi
if [ ! -d "${confluence_logfile}" ]; then
mkdir -p ${confluence_logfile}
fi
}
function processConfluenceProxySettings() {
if [ -n "${CONFLUENCE_PROXY_NAME}" ]; then
xmlstarlet ed -P -S -L --insert "//Connector[not(@proxyName)]" --type attr -n proxyName --value "${CONFLUENCE_PROXY_NAME}" ${CONF_INSTALL}/conf/server.xml
fi
if [ -n "${CONFLUENCE_PROXY_PORT}" ]; then
xmlstarlet ed -P -S -L --insert "//Connector[not(@proxyPort)]" --type attr -n proxyPort --value "${CONFLUENCE_PROXY_PORT}" ${CONF_INSTALL}/conf/server.xml
fi
if [ -n "${CONFLUENCE_PROXY_SCHEME}" ]; then
xmlstarlet ed -P -S -L --insert "//Connector[not(@scheme)]" --type attr -n scheme --value "${CONFLUENCE_PROXY_SCHEME}" ${CONF_INSTALL}/conf/server.xml
fi
}
function processContextPath() {
if [ -n "${CONFLUENCE_CONTEXT_PATH}" ]; then
xmlstarlet ed -P -S -L --update "//Context[contains(@docBase,'../confluence')]/@path" --value "${CONFLUENCE_CONTEXT_PATH}" ${CONF_INSTALL}/conf/server.xml
fi
}
function relayConfluenceLogFiles() {
TARGET_PROPERTY=1catalina.org.apache.juli.AsyncFileHandler.directory
sed -i "/${TARGET_PROPERTY}/d" ${CONF_INSTALL}/conf/logging.properties
echo "${TARGET_PROPERTY} = ${confluence_logfile}" >> ${CONF_INSTALL}/conf/logging.properties
TARGET_PROPERTY=2localhost.org.apache.juli.AsyncFileHandler.directory
sed -i "/${TARGET_PROPERTY}/d" ${CONF_INSTALL}/conf/logging.properties
echo "${TARGET_PROPERTY} = ${confluence_logfile}" >> ${CONF_INSTALL}/conf/logging.properties
TARGET_PROPERTY=3manager.org.apache.juli.AsyncFileHandler.directory
sed -i "/${TARGET_PROPERTY}/d" ${CONF_INSTALL}/conf/logging.properties
echo "${TARGET_PROPERTY} = ${confluence_logfile}" >> ${CONF_INSTALL}/conf/logging.properties
TARGET_PROPERTY=4host-manager.org.apache.juli.AsyncFileHandler.directory
sed -i "/${TARGET_PROPERTY}/d" ${CONF_INSTALL}/conf/logging.properties
echo "${TARGET_PROPERTY} = ${confluence_logfile}" >> ${CONF_INSTALL}/conf/logging.properties
}
function setConfluenceConfigurationProperty() {
local configurationProperty=$1
local configurationValue=$2
if [ -n "${configurationProperty}" ]; then
local propertyCount=$(xmlstarlet sel -t -v "count(//property[@name='${configurationProperty}'])" ${CONF_HOME}/confluence.cfg.xml)
if [ "${propertyCount}" = '0' ]; then
# Element does not exist, we insert new property
xmlstarlet ed --pf --inplace --subnode '//properties' --type elem --name 'property' --value "${configurationValue}" -i '//properties/property[not(@name)]' --type attr --name 'name' --value "${configurationProperty}" ${CONF_HOME}/confluence.cfg.xml
else
# Element exists, we update the existing property
xmlstarlet ed --pf --inplace --update "//property[@name='${configurationProperty}']" --value "${configurationValue}" ${CONF_HOME}/confluence.cfg.xml
fi
fi
}
function processConfluenceConfigurationSettings() {
local counter=1
if [ -f "${CONF_HOME}/confluence.cfg.xml" ]; then
for (( counter=1; ; counter++ ))
do
VAR_CONFLUENCE_CONFIG_PROPERTY="CONFLUENCE_CONFIG_PROPERTY$counter"
VAR_CONFLUENCE_CONFIG_VALUE="CONFLUENCE_CONFIG_VALUE$counter"
if [ -z "${!VAR_CONFLUENCE_CONFIG_PROPERTY}" ]; then
break
fi
setConfluenceConfigurationProperty ${!VAR_CONFLUENCE_CONFIG_PROPERTY} ${!VAR_CONFLUENCE_CONFIG_VALUE}
done
fi
}
function processCatalinaDefaultConfiguration() {
if [ -f "${CONF_INSTALL}/bin/setenv.sh" ]; then
sed -i "/export CATALINA_OPTS/d" ${CONF_INSTALL}/bin/setenv.sh
sed -i "/CATALINA_OPTS=/d" ${CONF_INSTALL}/bin/setenv.sh
echo 'CATALINA_OPTS="-Dconfluence.document.conversion.fontpath=/usr/share/fonts/truetype/msttcorefonts ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:-PrintGCDetails ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:+PrintGCDateStamps ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:-PrintTenuringDistribution ${CATALINA_OPTS}"
CATALINA_OPTS="-Xloggc:$LOGBASEABS/logs/gc-`date +%F_%H-%M-%S`.log ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:+UseGCLogFileRotation ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:NumberOfGCLogFiles=5 ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:GCLogFileSize=2M ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:G1ReservePercent=20 ${CATALINA_OPTS}"
CATALINA_OPTS="-Djava.awt.headless=true ${CATALINA_OPTS}"
CATALINA_OPTS="-Datlassian.plugins.enable.wait=300 ${CATALINA_OPTS}"
CATALINA_OPTS="-Xms1024m ${CATALINA_OPTS}"
CATALINA_OPTS="-Xmx1024m ${CATALINA_OPTS}"
CATALINA_OPTS="-XX:+UseG1GC ${CATALINA_OPTS}"
CATALINA_OPTS="${START_CONFLUENCE_JAVA_OPTS} ${CATALINA_OPTS}"
CATALINA_OPTS="-Dsynchrony.enable.xhr.fallback=true ${CATALINA_OPTS}"
CATALINA_OPTS="-Dorg.apache.tomcat.websocket.DEFAULT_BUFFER_SIZE=32768 ${CATALINA_OPTS}"
CATALINA_OPTS="-Dconfluence.context.path=${CONFLUENCE_CONTEXT_PATH} ${CATALINA_OPTS}"' >> ${CONF_INSTALL}/bin/setenv.sh
echo "export CATALINA_OPTS" >> ${CONF_INSTALL}/bin/setenv.sh
fi
}
function setCatalinaConfigurationProperty() {
local configurationProperty=$1
local configurationValue=$2
local catalinaproperty=""
if [ -n "${configurationProperty}" ]; then
sed -i "/${configurationProperty}/d" ${CONF_INSTALL}/bin/setenv.sh
catalinaproperty="CATALINA_OPTS=\""${configurationProperty}
if [ -n "${configurationValue}" ]; then
catalinaproperty=${catalinaproperty}${configurationValue}
fi
catalinaproperty=${catalinaproperty}" "'${CATALINA_OPTS}'"\""
echo ${catalinaproperty} >> ${CONF_INSTALL}/bin/setenv.sh
fi
}
function processCatalinaConfigurationSettings() {
local counter=1
local VAR_CATALINA_PARAMETER="CATALINA_PARAMETER1"
local VAR_CATALINA_PARAMETER_VALUE="CATALINA_PARAMETER_VALUE1"
if [ -n "${!VAR_CATALINA_PARAMETER}" ]; then
if [ -f "${CONF_INSTALL}/bin/setenv.sh" ]; then
sed -i "/export CATALINA_OPTS/d" ${CONF_INSTALL}/bin/setenv.sh
for (( counter=1; ; counter++ ))
do
VAR_CATALINA_PARAMETER="CATALINA_PARAMETER$counter"
VAR_CATALINA_PARAMETER_VALUE="CATALINA_PARAMETER_VALUE$counter"
if [ -z "${!VAR_CATALINA_PARAMETER}" ]; then
break
fi
setCatalinaConfigurationProperty ${!VAR_CATALINA_PARAMETER} ${!VAR_CATALINA_PARAMETER_VALUE}
done
echo "export CATALINA_OPTS" >> ${CONF_INSTALL}/bin/setenv.sh
fi
fi
}
if [ -n "${CONFLUENCE_DELAYED_START}" ]; then
sleep ${CONFLUENCE_DELAYED_START}
fi
createConfluenceTempDirectory
processConfluenceProxySettings
processContextPath
processConfluenceConfigurationSettings
if [ -n "${CATALINA_PARAMETER1}" ]; then
processCatalinaDefaultConfiguration
fi
if [ -n "${CATALINA_PARAMETER1}" ]; then
processCatalinaConfigurationSettings
fi
if [ -n "${CONFLUENCE_LOGFILE_LOCATION}" ]; then
processConfluenceLogfileSettings
relayConfluenceLogFiles
fi
if [ -n "${CONFLUENCE_CROWD_SSO}" ]; then
controlCrowdSSO ${CONFLUENCE_CROWD_SSO}
fi
if [ "$1" = 'confluence' ]; then
source /usr/bin/dockerwait
exec ${CONF_INSTALL}/bin/start-confluence.sh -fg
else
exec "$@"
fi