1
1
#! /usr/bin/env bash
2
+ # shellcheck disable=all
2
3
3
- set -e
4
+ # set -e
4
5
5
6
# performs mongod upgrades and engine migrations as configured
6
7
migrate_kvstore () {
7
- {{ splunk_home }}/bin/splunk migrate migrate-kvstore-36-40 || true
8
+ {{ splunk_home }}/bin/splunk migrate migrate-kvstore-36-40
8
9
9
10
{% if migrate_kvstore is defined %}
10
11
{{ splunk_home }}/bin/splunk start --accept-license --answer-yes --no-prompt $@
@@ -19,22 +20,45 @@ migrate_kvstore() {
19
20
20
21
# starts Splunk using the CLI
21
22
start_splunk () {
22
- # replace the process running this script with the process running Splunk
23
- # note: this "fixes" signal forwarding so that the trap for stop_splunk
24
- # should not be needed, however it has been included here in case it
25
- # occurs before the exec is complete
23
+ printf " Performing kvstore migration before starting Splunk\n"
26
24
migrate_kvstore
27
- exec {{ splunk_home }}/bin/splunk start --nodaemon --accept-license --answer-yes --no-prompt $@
25
+
26
+ printf " Starting Splunk with arguments ${* } \n"
27
+ {{ splunk_home }}/bin/splunk start --nodaemon --accept-license --answer-yes --no-prompt $@ &
28
+ splunk_pid=$!
29
+ printf " Splunk is now running with pid ${splunk_pid} \n"
30
+ wait_for_splunk_to_stop
28
31
}
29
32
30
33
# stops Splunk using the CLI
31
34
stop_splunk () {
32
- {{ splunk_home }}/bin/splunk stop $@ 2> /dev/null || true
35
+ printf " Stopping Splunk running with pid ${splunk_pid} for graceful shutdown\n"
36
+ {{ splunk_home }}/bin/splunk stop
37
+ if [ -f {{ splunk_home }}/var/run/splunk/conf-mutator.pid ]; then
38
+ printf " Found conf-mutator.pid file containing pid %d after shutdown, removing...\n" " $( cat {{ splunk_home }}/var/run/splunk/conf-mutator.pid) "
39
+ rm -vf {{ splunk_home }}/var/run/splunk/conf-mutator.pid
40
+ fi
41
+ }
42
+
43
+ wait_for_splunk_to_stop () {
44
+ wait -n ${splunk_pid}
45
+ printf " Entrypoint has detected that Splunk is no longer running and is now exiting\n"
46
+ }
47
+
48
+ # log graceful shutdown and call stop_splunk
49
+ graceful_shutdown () {
50
+ printf " Received SIGTERM interrupt, now stopping Splunk running with PID ${splunk_pid} for graceful shutdown\n"
51
+ printf " Stopping Splunk running with pid ${splunk_pid} for graceful shutdown\n"
52
+ {{ splunk_home }}/bin/splunk stop
53
+ if [ -f {{ splunk_home }}/var/run/splunk/conf-mutator.pid ]; then
54
+ printf " Found conf-mutator.pid file containing pid %d after shutdown, removing...\n" " $( cat {{ splunk_home }}/var/run/splunk/conf-mutator.pid) "
55
+ rm -vf {{ splunk_home }}/var/run/splunk/conf-mutator.pid
56
+ fi
33
57
}
34
58
35
59
# calls stop_splunk function when SIGINT and SIGTERM are received
36
60
# to allow for graceful shutdowns in Docker Swarm
37
- trap stop_splunk SIGINT SIGTERM
61
+ trap graceful_shutdown SIGTERM
38
62
39
63
# restarts Splunk using the CLI
40
64
restart_splunk () {
0 commit comments