-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
155 lines (132 loc) · 5.86 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
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
#!/bin/bash
set -e
if [ "$1" = 'splunk' ]; then
shift
sudo -HEu ${SPLUNK_USER} ${SPLUNK_HOME}/bin/splunk "$@"
elif [ "$1" = 'start-service' ]; then
# If user changed SPLUNK_USER to root we want to change permission for SPLUNK_HOME
if [[ "${SPLUNK_USER}:${SPLUNK_GROUP}" != "$(stat --format %U:%G ${SPLUNK_HOME})" ]]; then
chown -R ${SPLUNK_USER}:${SPLUNK_GROUP} ${SPLUNK_HOME}
fi
# If version file exists already - this Splunk has been configured before
__configured=false
if [[ -f ${SPLUNK_HOME}/etc/splunk.version ]]; then
__configured=true
fi
__license_ok=false
# If these files are different override etc folder (possible that this is upgrade or first start cases)
# Also override ownership of these files to splunk:splunk
if ! $(cmp --silent /var/opt/splunk/etc/splunk.version ${SPLUNK_HOME}/etc/splunk.version); then
cp -fR /var/opt/splunk/etc ${SPLUNK_HOME}
chown -R ${SPLUNK_USER}:${SPLUNK_GROUP} ${SPLUNK_HOME}/etc
chown -R ${SPLUNK_USER}:${SPLUNK_GROUP} ${SPLUNK_HOME}/var
else
__license_ok=true
fi
if tty -s; then
__license_ok=true
fi
if [[ "$SPLUNK_START_ARGS" == *"--accept-license"* ]]; then
__license_ok=true
fi
if [[ $__license_ok == "false" ]]; then
cat << EOF
Splunk Enterprise
==============
Available Options:
- Launch container in Interactive mode "-it" to review and accept
end user license agreement
- If you have reviewed and accepted the license, start container
with the environment variable:
SPLUNK_START_ARGS=--accept-license --seed-passwd <your password>
Usage:
docker run -it splunk/enterprise:7.1.2
docker run --env SPLUNK_START_ARGS="--accept-license --seed-passwd <your password>" splunk/enterprise:7.1.2
EOF
exit 1
fi
if [[ $__configured == "false" ]]; then
# If we have not configured yet allow user to specify some commands which can be executed before we start Splunk for the first time
if [[ -n ${SPLUNK_BEFORE_START_CMD} ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk ${SPLUNK_BEFORE_START_CMD}"
fi
for n in {1..30}; do
if [[ -n $(eval echo \$\{SPLUNK_BEFORE_START_CMD_${n}\}) ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk $(eval echo \$\{SPLUNK_BEFORE_START_CMD_${n}\})"
else
# We do not want to iterate all, if one in the sequence is not set
break
fi
done
fi
sudo -HEu ${SPLUNK_USER} ${SPLUNK_HOME}/bin/splunk start ${SPLUNK_START_ARGS}
trap "sudo -HEu ${SPLUNK_USER} ${SPLUNK_HOME}/bin/splunk stop" SIGINT SIGTERM EXIT
# If this is first time we start this splunk instance
if [[ $__configured == "false" ]]; then
__restart_required=false
# Setup deployment server
if [[ ${SPLUNK_ENABLE_DEPLOY_SERVER} == "true" ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk enable deploy-server -auth admin:changeme"
__restart_required=true
fi
# Setup deployment client
# http://docs.splunk.com/Documentation/Splunk/latest/Updating/Configuredeploymentclients
if [[ -n ${SPLUNK_DEPLOYMENT_SERVER} ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk set deploy-poll ${SPLUNK_DEPLOYMENT_SERVER} -auth admin:changeme"
__restart_required=true
fi
if [[ "$__restart_required" == "true" ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk restart"
fi
# Setup listening
# http://docs.splunk.com/Documentation/Splunk/latest/Forwarding/Enableareceiver
if [[ -n ${SPLUNK_ENABLE_LISTEN} ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk enable listen ${SPLUNK_ENABLE_LISTEN} -auth admin:changeme ${SPLUNK_ENABLE_LISTEN_ARGS}"
fi
# Setup forwarding server
# http://docs.splunk.com/Documentation/Splunk/latest/Forwarding/Deployanixdfmanually
if [[ -n ${SPLUNK_FORWARD_SERVER} ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk add forward-server ${SPLUNK_FORWARD_SERVER} -auth admin:changeme ${SPLUNK_FORWARD_SERVER_ARGS}"
fi
for n in {1..10}; do
if [[ -n $(eval echo \$\{SPLUNK_FORWARD_SERVER_${n}\}) ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk add forward-server $(eval echo \$\{SPLUNK_FORWARD_SERVER_${n}\}) -auth admin:changeme $(eval echo \$\{SPLUNK_FORWARD_SERVER_${n}_ARGS\})"
else
# We do not want to iterate all, if one in the sequence is not set
break
fi
done
# Setup monitoring
# http://docs.splunk.com/Documentation/Splunk/latest/Data/MonitorfilesanddirectoriesusingtheCLI
# http://docs.splunk.com/Documentation/Splunk/latest/Data/Monitornetworkports
if [[ -n ${SPLUNK_ADD} ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk add ${SPLUNK_ADD} -auth admin:changeme"
fi
for n in {1..30}; do
if [[ -n $(eval echo \$\{SPLUNK_ADD_${n}\}) ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk add $(eval echo \$\{SPLUNK_ADD_${n}\}) -auth admin:changeme"
else
# We do not want to iterate all, if one in the sequence is not set
break
fi
done
# Execute anything
if [[ -n ${SPLUNK_CMD} ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk ${SPLUNK_CMD}"
fi
for n in {1..30}; do
if [[ -n $(eval echo \$\{SPLUNK_CMD_${n}\}) ]]; then
sudo -HEu ${SPLUNK_USER} sh -c "${SPLUNK_HOME}/bin/splunk $(eval echo \$\{SPLUNK_CMD_${n}\})"
else
# We do not want to iterate all, if one in the sequence is not set
break
fi
done
fi
sudo -HEu ${SPLUNK_USER} tail -n 0 -f ${SPLUNK_HOME}/var/log/splunk/splunkd_stderr.log &
wait
elif [ "$1" = 'splunk-bash' ]; then
sudo -u ${SPLUNK_USER} /bin/bash --init-file ${SPLUNK_HOME}/bin/setSplunkEnv
else
"$@"
fi