-
Notifications
You must be signed in to change notification settings - Fork 3
/
entrypoint.sh
51 lines (43 loc) · 1.39 KB
/
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
#!/bin/bash
set -e
: ${MMS_SERVER:=https://mms.mongodb.com}
: ${MMS_MUNIN:=true}
: ${MMS_CHECK_SSL_CERTS:=true}
if [ ! "$MMS_API_KEY" ]; then
{
echo 'error: MMS_API_KEY was not specified'
echo 'try something like: docker run -e MMS_API_KEY=... ...'
echo '(see https://mms.mongodb.com/settings/monitoring-agent for your mmsApiKey)'
echo
echo 'Other optional variables:'
echo ' - MMS_SERVER='"$MMS_SERVER"
echo ' - MMS_MUNIN='"$MMS_MUNIN"
echo ' - MMS_CHECK_SSL_CERTS='"$MMS_CHECK_SSL_CERTS"
} >&2
exit 1
fi
if [ ! "$MMS_GROUP_ID" ]; then
{
echo 'error: MMS_GROUP_ID was not specified'
echo 'try something like: docker run -e MMS_GROUP_ID=... ...'
echo '(see Mongo Cloud Console for your mmsGroupId)'
} >&2
exit 1
fi
# "sed -i" can't operate on the file directly, and it tries to make a copy in the same directory, which our user can't do
config_tmp="$(mktemp)"
cat /etc/mongodb-mms/monitoring-agent.config > "$config_tmp"
set_config() {
key="$1"
value="$2"
sed_escaped_value="$(echo "$value" | sed 's/[\/&]/\\&/g')"
sed -ri "s/^($key)[ ]*=.*$/\1 = $sed_escaped_value/" "$config_tmp"
}
set_config mmsApiKey "$MMS_API_KEY"
set_config mmsGroupId "$MMS_GROUP_ID"
set_config mmsBaseUrl "$MMS_SERVER"
set_config enableMunin "$MMS_MUNIN"
set_config sslRequireValidServerCertificates "$MMS_CHECK_SSL_CERTS"
cat "$config_tmp" > /etc/mongodb-mms/monitoring-agent.config
rm "$config_tmp"
exec "$@"