-
Notifications
You must be signed in to change notification settings - Fork 4
/
configure.sh
executable file
·303 lines (252 loc) · 14 KB
/
configure.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/bin/sh
OPENSHIFT_CONFIG_FILE=$AMQ_HOME/conf/openshift-activemq.xml
CONFIG_FILE=$AMQ_HOME/conf/activemq.xml
OPENSHIFT_LOGIN_FILE=$AMQ_HOME/conf/openshift-login.config
LOGIN_FILE=$AMQ_HOME/conf/login.config
OPENSHIFT_USERS_FILE=$AMQ_HOME/conf/openshift-users.properties
USERS_FILE=$AMQ_HOME/conf/users.properties
# Finds the environment variable and returns its value if found.
# Otherwise returns the default value if provided.
#
# Arguments:
# $1 env variable name to check
# $2 default value if environemnt variable was not set
function find_env() {
var=`printenv "$1"`
# If environment variable exists
if [ -n "$var" ]; then
echo $var
else
echo $2
fi
}
function checkViewEndpointsPermission() {
if [ "${AMQ_MESH_DISCOVERY_TYPE}" = "kube" ]; then
if [ -n "${AMQ_MESH_SERVICE_NAMESPACE+_}" ] && [ -n "${AMQ_MESH_SERVICE_NAME+_}" ]; then
endpointsUrl="https://${KUBERNETES_SERVICE_HOST:-kubernetes.default.svc}:${KUBERNETES_SERVICE_PORT:-443}/api/v1/namespaces/${AMQ_MESH_SERVICE_NAMESPACE}/endpoints/${AMQ_MESH_SERVICE_NAME}"
endpointsAuth="Authorization: Bearer $(cat /var/run/secrets/kubernetes.io/serviceaccount/token)"
endpointsCode=$(curl -s -o /dev/null -w "%{http_code}" -G -k -H "${endpointsAuth}" ${endpointsUrl})
if [ "${endpointsCode}" = "200" ]; then
echo "Service account has sufficient permissions to view endpoints in kubernetes (HTTP ${endpointsCode}). Mesh will be available."
elif [ "${endpointsCode}" = "403" ]; then
>&2 echo "WARNING: Service account has insufficient permissions to view endpoints in kubernetes (HTTP ${endpointsCode}). Mesh will be unavailable. Please refer to the documentation for configuration."
else
>&2 echo "WARNING: Service account unable to test permissions to view endpoints in kubernetes (HTTP ${endpointsCode}). Mesh will be unavailable. Please refer to the documentation for configuration."
fi
else
>&2 echo "WARNING: Environment variables AMQ_MESH_SERVICE_NAMESPACE and AMQ_MESH_SERVICE_NAME both need to be defined when using AMQ_MESH_DISCOVERY_TYPE=\"kube\". Mesh will be unavailable. Please refer to the documentation for configuration."
fi
fi
}
function configureMesh() {
serviceName="${AMQ_MESH_SERVICE_NAME}"
username="${AMQ_USER}"
password="${AMQ_PASSWORD}"
discoveryType="${AMQ_MESH_DISCOVERY_TYPE:-dns}"
if [ -n "${serviceName}" ] ; then
networkConnector=""
if [ -n "${username}" -a -n "${password}" ] ; then
networkConnector="<networkConnector userName=\"${username}\" password=\"${password}\" uri=\"${discoveryType}://${serviceName}:61616/?transportType=tcp\" messageTTL=\"-1\" consumerTTL=\"1\" />"
else
networkConnector="<networkConnector uri=\"${discoveryType}://${serviceName}:61616/?transportType=tcp\" messageTTL=\"-1\" consumerTTL=\"1\" />"
fi
sed -i "s|<!-- ##### MESH_CONFIG ##### -->|${networkConnector}|" "$CONFIG_FILE"
fi
}
function configureAuthentication() {
username="${AMQ_USER}"
password="${AMQ_PASSWORD}"
if [ -n "${username}" -a -n "${password}" ] ; then
sed -i "s|##### AUTHENTICATION #####|${username}=${password}|" "${USERS_FILE}"
authentication="<jaasAuthenticationPlugin configuration=\"activemq\" />"
else
authentication="<jaasAuthenticationPlugin configuration=\"activemq-guest\" />"
fi
sed -i "s|<!-- ##### AUTHENTICATION ##### -->|${authentication}|" "$CONFIG_FILE"
}
function configureDestinations() {
IFS=',' read -a queues <<< ${AMQ_QUEUES}
IFS=',' read -a topics <<< ${AMQ_TOPICS}
if [ "${#queues[@]}" -ne "0" -o "${#topics[@]}" -ne "0" ]; then
destinations="<destinations>"
if [ "${#queues[@]}" -ne "0" ]; then
for queue in ${queues[@]}; do
destinations="${destinations}<queue physicalName=\"${queue}\"/>"
done
fi
if [ "${#topics[@]}" -ne "0" ]; then
for topic in ${topics[@]}; do
destinations="${destinations}<topic physicalName=\"${topic}\"/>"
done
fi
destinations="${destinations}</destinations>"
sed -i "s|<!-- ##### DESTINATIONS ##### -->|${destinations}|" "$CONFIG_FILE"
fi
}
function sslPartial() {
[ -n "$AMQ_KEYSTORE_TRUSTSTORE_DIR" -o -n "$AMQ_KEYSTORE" -o -n "$AMQ_TRUSTSTORE" -o -n "$AMQ_KEYSTORE_PASSWORD" -o -n "$AMQ_TRUSTSTORE_PASSWORD" ]
}
function sslEnabled() {
[ -n "$AMQ_KEYSTORE_TRUSTSTORE_DIR" -a -n "$AMQ_KEYSTORE" -a -n "$AMQ_TRUSTSTORE" -a -n "$AMQ_KEYSTORE_PASSWORD" -a -n "$AMQ_TRUSTSTORE_PASSWORD" ]
}
function configureSSL() {
sslDir=$(find_env "AMQ_KEYSTORE_TRUSTSTORE_DIR" "")
keyStoreFile=$(find_env "AMQ_KEYSTORE" "")
trustStoreFile=$(find_env "AMQ_TRUSTSTORE" "")
if sslEnabled ; then
keyStorePassword=$(find_env "AMQ_KEYSTORE_PASSWORD" "")
trustStorePassword=$(find_env "AMQ_TRUSTSTORE_PASSWORD" "")
keyStorePath="$sslDir/$keyStoreFile"
trustStorePath="$sslDir/$trustStoreFile"
sslElement="<sslContext>\n\
<sslContext keyStore=\"file:$keyStorePath\"\n\
keyStorePassword=\"$keyStorePassword\"\n\
trustStore=\"file:$trustStorePath\"\n\
trustStorePassword=\"$trustStorePassword\" />\n\
</sslContext>"
sed -i "s|<!-- ##### SSL_CONTEXT ##### -->|${sslElement}|" "$CONFIG_FILE"
elif sslPartial ; then
echo "WARNING! Partial ssl configuration, the ssl context WILL NOT be configured."
fi
}
function configureStoreUsage() {
storeUsage=$(find_env "AMQ_STORAGE_USAGE_LIMIT" "100 gb")
sed -i "s|##### STORE_USAGE #####|${storeUsage}|" "$CONFIG_FILE"
}
function configureTransportOptions() {
IFS=',' read -a transports <<< $(find_env "AMQ_TRANSPORTS" "openwire,mqtt,amqp,stomp")
maxConnections=$(find_env "AMQ_MAX_CONNECTIONS" "1000")
maxFrameSize=$(find_env "AMQ_FRAME_SIZE" "104857600")
if [ "${#transports[@]}" -ne "0" ]; then
transportConnectors="<transportConnectors>"
for transport in ${transports[@]}; do
case "${transport}" in
"openwire")
transportConnectors="${transportConnectors}\n <transportConnector name=\"openwire\" uri=\"tcp://0.0.0.0:61616?maximumConnections=${maxConnections}\&wireFormat.maxFrameSize=${maxFrameSize}\" />"
if sslEnabled ; then
transportConnectors="${transportConnectors}\n <transportConnector name=\"ssl\" uri=\"ssl://0.0.0.0:61617?maximumConnections=${maxConnections}\&wireFormat.maxFrameSize=${maxFrameSize}\" />"
fi
;;
"mqtt")
transportConnectors="${transportConnectors}\n <transportConnector name=\"mqtt\" uri=\"mqtt://0.0.0.0:1883?maximumConnections=${maxConnections}\&wireFormat.maxFrameSize=${maxFrameSize}\" />"
if sslEnabled ; then
transportConnectors="${transportConnectors}\n <transportConnector name=\"mqtt+ssl\" uri=\"mqtt+ssl://0.0.0.0:8883?maximumConnections=${maxConnections}\&wireFormat.maxFrameSize=${maxFrameSize}\" />"
fi
;;
"amqp")
transportConnectors="${transportConnectors}\n <transportConnector name=\"amqp\" uri=\"amqp://0.0.0.0:5672?maximumConnections=${maxConnections}\&wireFormat.maxFrameSize=${maxFrameSize}\" />"
if sslEnabled ; then
transportConnectors="${transportConnectors}\n <transportConnector name=\"amqp+ssl\" uri=\"amqp+ssl://0.0.0.0:5671?maximumConnections=${maxConnections}\&wireFormat.maxFrameSize=${maxFrameSize}\" />"
fi
;;
"stomp")
transportConnectors="${transportConnectors}\n <transportConnector name=\"stomp\" uri=\"stomp://0.0.0.0:61613?maximumConnections=${maxConnections}\&wireFormat.maxFrameSize=${maxFrameSize}\" />"
if sslEnabled ; then
transportConnectors="${transportConnectors}\n <transportConnector name=\"stomp+ssl\" uri=\"stomp+ssl://0.0.0.0:61612?maximumConnections=${maxConnections}\&wireFormat.maxFrameSize=${maxFrameSize}\" />"
fi
;;
esac
done
transportConnectors="${transportConnectors}\n </transportConnectors>"
sed -i "s|<!-- ##### TRANSPORT_CONNECTORS ##### -->|${transportConnectors}|" "$CONFIG_FILE"
fi
}
function configurePostgresPersistence() {
PERSISTENCE_ADAPTER_SNIPPET=$AMQ_HOME/conf/postgres-jdbc-persistence-adapter-snippet.xml
DATASOURCE_SNIPPET=$AMQ_HOME/conf/postgres-datasource-snippet.xml
amqLockKeepAlivePeriod=$(find_env "AMQ_LOCK_KEEP_ALIVE_PERIOD" "5000")
amqCreateTablesOnStart=$(find_env "AMQ_DB_CREATE_TABLE_ON_STARTUP" "true")
amqLockAquireSleepInterval=$(find_env "AMQ_LOCK_ACQUIRE_SLEEP_INTERVAL" "10000")
amqMaxAllowableDiffFromDbTime=$(find_env "AMQ_MAX_ALLOWABLE_DIFF_FROM_DB_TIME" "1000")
jdbcUrl=$(find_env "JDBC_URL" "jdbc:oracle:thin:@oracle_host:1521:ora1")
jdbcUser=$(find_env "JDBC_USER" "oracle")
jdbcPassword=$(find_env "JDBC_PASSWORD" "sqladmin")
sed -i "s|#amqLockKeepAlivePeriod|${amqLockKeepAlivePeriod}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqCreateTablesOnStart|${amqCreateTablesOnStart}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqLockAquireSleepInterval|${amqLockAquireSleepInterval}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqMaxAllowableDiffFromDbTime|${amqMaxAllowableDiffFromDbTime}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#jdbcUrl|${jdbcUrl}|" "$DATASOURCE_SNIPPET"
sed -i "s|#jdbcUser|${jdbcUser}|" "$DATASOURCE_SNIPPET"
sed -i "s|#jdbcPassword|${jdbcPassword}|" "$DATASOURCE_SNIPPET"
echo "replacing PERSISTENCE_ADAPTER with content from: ${PERSISTENCE_ADAPTER_SNIPPET}"
paSnippet=$(cat $PERSISTENCE_ADAPTER_SNIPPET)
echo "replacing <!-- ##### PERSISTENCE_ADAPTER ##### --> in ${CONFIG_FILE} with content : ${paSnippet}"
sed -i "s|<!-- ##### PERSISTENCE_ADAPTER ##### -->|${paSnippet}|" "$CONFIG_FILE"
echo "replacing DATASOURCE_BEAN with content from: ${DATASOURCE_SNIPPET}"
dsSnippet=$(cat $DATASOURCE_SNIPPET)
echo "replacing <!-- ##### DATASOURCE_BEAN ##### --> in ${CONFIG_FILE} with content : ${dsSnippet}"
sed -i "s|<!-- ##### DATASOURCE_BEAN ##### -->|${dsSnippet}|" "$CONFIG_FILE"
}
function configureOraclePersistence() {
PERSISTENCE_ADAPTER_SNIPPET=$AMQ_HOME/conf/oracle-jdbc-persistence-adapter-snippet.xml
DATASOURCE_SNIPPET=$AMQ_HOME/conf/oracle-datasource-snippet.xml
amqLockKeepAlivePeriod=$(find_env "AMQ_LOCK_KEEP_ALIVE_PERIOD" "5000")
amqCreateTablesOnStart=$(find_env "AMQ_DB_CREATE_TABLE_ON_STARTUP" "true")
amqLockAquireSleepInterval=$(find_env "AMQ_LOCK_ACQUIRE_SLEEP_INTERVAL" "10000")
amqMaxAllowableDiffFromDbTime=$(find_env "AMQ_MAX_ALLOWABLE_DIFF_FROM_DB_TIME" "1000")
jdbcUrl=$(find_env "JDBC_URL" "jdbc:oracle:thin:@oracle_host:1521:ora1")
jdbcUser=$(find_env "JDBC_USER" "oracle")
jdbcPassword=$(find_env "JDBC_PASSWORD" "sqladmin")
sed -i "s|#amqLockKeepAlivePeriod|${amqLockKeepAlivePeriod}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqCreateTablesOnStart|${amqCreateTablesOnStart}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqLockAquireSleepInterval|${amqLockAquireSleepInterval}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqMaxAllowableDiffFromDbTime|${amqMaxAllowableDiffFromDbTime}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#jdbcUrl|${jdbcUrl}|" "$DATASOURCE_SNIPPET"
sed -i "s|#jdbcUser|${jdbcUser}|" "$DATASOURCE_SNIPPET"
sed -i "s|#jdbcPassword|${jdbcPassword}|" "$DATASOURCE_SNIPPET"
echo "replacing PERSISTENCE_ADAPTER with content from: ${PERSISTENCE_ADAPTER_SNIPPET}"
paSnippet=$(cat $PERSISTENCE_ADAPTER_SNIPPET)
echo "replacing <!-- ##### PERSISTENCE_ADAPTER ##### --> in ${CONFIG_FILE} with content : ${paSnippet}"
sed -i "s|<!-- ##### PERSISTENCE_ADAPTER ##### -->|${paSnippet}|" "$CONFIG_FILE"
echo "replacing DATASOURCE_BEAN with content from: ${DATASOURCE_SNIPPET}"
dsSnippet=$(cat $DATASOURCE_SNIPPET)
echo "replacing <!-- ##### DATASOURCE_BEAN ##### --> in ${CONFIG_FILE} with content : ${dsSnippet}"
sed -i "s|<!-- ##### DATASOURCE_BEAN ##### -->|${dsSnippet}|" "$CONFIG_FILE"
}
function configureHSQLPersistence() {
PERSISTENCE_ADAPTER_SNIPPET=$AMQ_HOME/conf/hsql-jdbc-persistence-adapter-snippet.xml
DATASOURCE_SNIPPET=$AMQ_HOME/conf/hsql-datasource-snippet.xml
amqLockKeepAlivePeriod=$(find_env "AMQ_LOCK_KEEP_ALIVE_PERIOD" "5000")
amqCreateTablesOnStart=$(find_env "AMQ_DB_CREATE_TABLE_ON_STARTUP" "true")
amqLockAquireSleepInterval=$(find_env "AMQ_LOCK_ACQUIRE_SLEEP_INTERVAL" "10000")
amqMaxAllowableDiffFromDbTime=$(find_env "AMQ_MAX_ALLOWABLE_DIFF_FROM_DB_TIME" "1000")
sed -i "s|#amqLockKeepAlivePeriod|${amqLockKeepAlivePeriod}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqCreateTablesOnStart|${amqCreateTablesOnStart}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqLockAquireSleepInterval|${amqLockAquireSleepInterval}|" "$PERSISTENCE_ADAPTER_SNIPPET"
sed -i "s|#amqMaxAllowableDiffFromDbTime|${amqMaxAllowableDiffFromDbTime}|" "$PERSISTENCE_ADAPTER_SNIPPET"
echo "replacing PERSISTENCE_ADAPTER with content from: ${PERSISTENCE_ADAPTER_SNIPPET}"
paSnippet=$(cat $PERSISTENCE_ADAPTER_SNIPPET)
echo "replacing <!-- ##### PERSISTENCE_ADAPTER ##### --> in ${CONFIG_FILE} with content : ${paSnippet}"
sed -i "s|<!-- ##### PERSISTENCE_ADAPTER ##### -->|${paSnippet}|" "$CONFIG_FILE"
echo "replacing DATASOURCE_BEAN with content from: ${DATASOURCE_SNIPPET}"
dsSnippet=$(cat $DATASOURCE_SNIPPET)
echo "replacing <!-- ##### DATASOURCE_BEAN ##### --> in ${CONFIG_FILE} with content : ${dsSnippet}"
sed -i "s|<!-- ##### DATASOURCE_BEAN ##### -->|${dsSnippet}|" "$CONFIG_FILE"
}
function configureJdbcPersistence() {
dbType=$(find_env "AMQ_DB_TYPE" "oracle")
echo "dbType is ${dbType}"
if [ "$dbType" == "oracle" ]
then
configureOraclePersistence
fi
if [ "$dbType" == "postgres" ]
then
configurePostgresPersistence
fi
if [ "$dbType" == "hsql" ]
then
configureHSQLPersistence
fi
}
cp "${OPENSHIFT_CONFIG_FILE}" "${CONFIG_FILE}"
cp "${OPENSHIFT_LOGIN_FILE}" "${LOGIN_FILE}"
cp "${OPENSHIFT_USERS_FILE}" "${USERS_FILE}"
configureAuthentication
configureDestinations
configureSSL
configureStoreUsage
configureTransportOptions
checkViewEndpointsPermission
configureMesh
configureJdbcPersistence