forked from Graylog2/graylog-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health_check.sh
executable file
·112 lines (94 loc) · 3.36 KB
/
health_check.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
#!/bin/bash
source /etc/profile
# See "Web & Rest API" @ https://docs.graylog.org/docs/server-conf
#
# if `http_publish_uri` is given, use that for healthcheck,
# if not take `http_bind_address` what defaults to 127.0.0.1
# if nothing is set.
#
# defaults
proto=http
http_bind_address=127.0.0.1:9000
# check if configuration file is given and grep for variable
if [[ -f "${GRAYLOG_HOME}"/data/config/graylog.conf ]]
then
# try to grep the variable from a mounted configuration
http_publish_uri=$(grep "^http_publish_uri" "${GRAYLOG_HOME}"/data/config/graylog.conf | awk -F '=' '{print $2}' | awk '{$1=$1};1')
http_bind_address=$(grep "^http_bind_address" "${GRAYLOG_HOME}"/data/config/graylog.conf | awk -F '=' '{print $2}' | awk '{$1=$1};1')
http_enable_tls=$(grep "^http_enable_tls" "${GRAYLOG_HOME}"/data/config/graylog.conf | awk -F '=' '{print $2}' | awk '{$1=$1};1')
# FIX https://github.com/Graylog2/graylog-docker/issues/102
# This will remove the protocol from the URI if set via
# configuration.
# not the smartest solution currently but a working
# TODO: find a better way or maybe write a function
# shellcheck disable=SC2001
if [[ ! -z ${http_publish_uri} ]]
then
# remove the protocol from the URI
proton="$(echo "${http_publish_uri}" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
url=$(echo "${http_publish_uri}" | sed -e s,"$proton",,g)
# we want to be sure to use https if enable
# currently this looks like the best solution to cut
# the protocoll away and set it based on
# the fact if TLS is enabled or not
http_publish_uri="${url}"
fi
fi
# try to get the data from environment variables
# they will always override all other settings
# shellcheck disable=SC2001
if [[ ! -z "${GRAYLOG_HTTP_PUBLISH_URI}" ]]
then
# remove the protocol from the URI
proton="$(echo "${GRAYLOG_HTTP_PUBLISH_URI}" | grep :// | sed -e's,^\(.*://\).*,\1,g')"
url=$(echo "${GRAYLOG_HTTP_PUBLISH_URI}" | sed -e s,"$proton",,g)
# we want to be sure to use https if enable
# currently this looks like the best solution to cut
# the protocoll away and set it based on
# the fact if TLS is enabled or not
http_publish_uri="${url}"
fi
if [[ ! -z "${GRAYLOG_HTTP_BIND_ADDRESS}" ]]
then
http_bind_address="${GRAYLOG_HTTP_BIND_ADDRESS}"
fi
if [[ ! -z "${GRAYLOG_HTTP_ENABLE_TLS}" ]]
then
http_enable_tls="${GRAYLOG_HTTP_ENABLE_TLS}"
fi
# if configured set https
[[ ! -z "${http_enable_tls}" ]] && [[ ${http_enable_tls} = "true" ]] && proto=https
# when HTTP_PUBLISH_URI is given that is used for the healtcheck
# otherwise HTTP_BIND_ADDRESS
if [[ ! -z "${http_bind_address}" ]]
then
check_url="${proto}"://"${http_bind_address}"
else
# we will never run into this - but
# never say never
echo "not possible to get Graylog listen URI - abort"
exit 1
fi
if [[ ! -z "${http_publish_uri}" ]]
then
check_url="${proto}"://"${http_publish_uri}"
fi
if [[ -z "${check_url}" ]]
then
echo "Not possible to get Graylog listen URI - abort"
exit 1
fi
# FIX https://github.com/Graylog2/graylog-docker/issues/156
# ignore self-signed certificates for the real URL, not only for localhost
if curl --silent --insecure --fail "${check_url}"/api
then
exit 0
fi
# FIX https://github.com/Graylog2/graylog-docker/issues/101
# When the above check fails fall back to localhost
# This is not the most elegant solution but a working one
if curl --silent --insecure --fail http://127.0.0.1/api
then
exit 0
fi
exit 1