@@ -35,6 +35,9 @@ trap teardown SIGINT SIGTERM
3535
3636prep_ansible () {
3737 cd ${SPLUNK_ANSIBLE_HOME}
38+ if [ ` whoami` == " ${SPLUNK_USER} " ]; then
39+ sed -i -e " s,^become\\ s*=.*,become = false," ansible.cfg
40+ fi
3841 if [[ " $DEBUG " == " true" ]]; then
3942 ansible-playbook --version
4043 python inventory/environ.py --write-to-file
@@ -54,33 +57,36 @@ watch_for_failure(){
5457 echo
5558 user_permission_change
5659 # Any crashes/errors while Splunk is running should get logged to splunkd_stderr.log and sent to the container's stdout
60+ if [ ` whoami` != " ${SPLUNK_USER} " ]; then
61+ RUN_AS_SPLUNK=" sudo -u ${SPLUNK_USER} "
62+ fi
5763 if [ -z " $SPLUNK_TAIL_FILE " ]; then
58- sudo -u ${SPLUNK_USER } tail -n 0 -f ${SPLUNK_HOME} /var/log/splunk/splunkd_stderr.log &
64+ ${RUN_AS_SPLUNK } tail -n 0 -f ${SPLUNK_HOME} /var/log/splunk/splunkd_stderr.log &
5965 else
60- sudo -u ${SPLUNK_USER } tail -n 0 -f ${SPLUNK_TAIL_FILE} &
66+ ${RUN_AS_SPLUNK } tail -n 0 -f ${SPLUNK_TAIL_FILE} &
6167 fi
6268 wait
6369}
6470
6571create_defaults () {
66- createdefaults.py
72+ createdefaults.py
6773}
6874
6975start_and_exit () {
70- if [ -z " $SPLUNK_PASSWORD " ]
71- then
72- echo " WARNING: No password ENV var. Stack may fail to provision if splunk.password is not set in ENV or a default.yml"
73- fi
76+ if [ -z " $SPLUNK_PASSWORD " ]
77+ then
78+ echo " WARNING: No password ENV var. Stack may fail to provision if splunk.password is not set in ENV or a default.yml"
79+ fi
7480 sh -c " echo 'starting' > ${CONTAINER_ARTIFACT_DIR} /splunk-container.state"
7581 setup
76- prep_ansible
82+ prep_ansible
7783 ansible-playbook $ANSIBLE_EXTRA_FLAGS -i inventory/environ.py site.yml
7884}
7985
8086start () {
81- trap teardown EXIT
87+ trap teardown EXIT
8288 start_and_exit
83- watch_for_failure
89+ watch_for_failure
8490}
8591
8692configure_multisite () {
@@ -89,58 +95,58 @@ configure_multisite() {
8995}
9096
9197restart (){
92- trap teardown EXIT
98+ trap teardown EXIT
9399 sh -c " echo 'restarting' > ${CONTAINER_ARTIFACT_DIR} /splunk-container.state"
94- prep_ansible
95- ${SPLUNK_HOME} /bin/splunk stop 2> /dev/null || true
100+ prep_ansible
101+ ${SPLUNK_HOME} /bin/splunk stop 2> /dev/null || true
96102 ansible-playbook -i inventory/environ.py start.yml
97103 watch_for_failure
98104}
99105
100106user_permission_change (){
101107 if [[ " $STEPDOWN_ANSIBLE_USER " == " true" ]]; then
102- bash -c " sudo deluser -q ansible sudo"
108+ bash -c " sudo deluser -q ansible sudo"
103109 fi
104110}
105111
106112help () {
107113 cat << EOF
108- ____ _ _ __
114+ ____ _ _ __
109115 / ___| _ __ | |_ _ _ __ | | __ \ \\
110116 \___ \| '_ \| | | | | '_ \| |/ / \ \\
111- ___) | |_) | | |_| | | | | < / /
117+ ___) | |_) | | |_| | | | | < / /
112118 |____/| .__/|_|\__,_|_| |_|_|\_\ /_/
113- |_|
119+ |_|
114120========================================
115121
116122Environment Variables:
117- * SPLUNK_USER - user under which to run Splunk (default: splunk)
118- * SPLUNK_GROUP - group under which to run Splunk (default: splunk)
119- * SPLUNK_HOME - home directory where Splunk gets installed (default: /opt/splunk)
120- * SPLUNK_START_ARGS - arguments to pass into the Splunk start command; you must include '--accept-license' to start Splunk (default: none)
121- * SPLUNK_ROLE - the role of this Splunk instance (default: splunk_standalone)
122- Acceptable values:
123- - splunk_standalone
124- - splunk_search_head
125- - splunk_indexer
126- - splunk_deployer
127- - splunk_license_master
128- - splunk_cluster_master
129- - splunk_heavy_forwarder
130- * SPLUNK_LICENSE_URI - URI or local file path (absolute path in the container) to a Splunk license
131- * SPLUNK_STANDALONE_URL, SPLUNK_INDEXER_URL, ... - comma-separated list of resolvable aliases to properly bring-up a distributed environment.
132- This is optional for standalones, but required for multi-node Splunk deployments.
133- * SPLUNK_BUILD_URL - URL to a Splunk build which will be installed (instead of the image's default build)
134- * SPLUNK_APPS_URL - comma-separated list of URLs to Splunk apps which will be downloaded and installed
123+ * SPLUNK_USER - user under which to run Splunk (default: splunk)
124+ * SPLUNK_GROUP - group under which to run Splunk (default: splunk)
125+ * SPLUNK_HOME - home directory where Splunk gets installed (default: /opt/splunk)
126+ * SPLUNK_START_ARGS - arguments to pass into the Splunk start command; you must include '--accept-license' to start Splunk (default: none)
127+ * SPLUNK_ROLE - the role of this Splunk instance (default: splunk_standalone)
128+ Acceptable values:
129+ - splunk_standalone
130+ - splunk_search_head
131+ - splunk_indexer
132+ - splunk_deployer
133+ - splunk_license_master
134+ - splunk_cluster_master
135+ - splunk_heavy_forwarder
136+ * SPLUNK_LICENSE_URI - URI or local file path (absolute path in the container) to a Splunk license
137+ * SPLUNK_STANDALONE_URL, SPLUNK_INDEXER_URL, ... - comma-separated list of resolvable aliases to properly bring-up a distributed environment.
138+ This is optional for standalones, but required for multi-node Splunk deployments.
139+ * SPLUNK_BUILD_URL - URL to a Splunk build which will be installed (instead of the image's default build)
140+ * SPLUNK_APPS_URL - comma-separated list of URLs to Splunk apps which will be downloaded and installed
135141
136142Examples:
137- * docker run -it -p 8000:8000 splunk/splunk start
138- * docker run -it -e SPLUNK_START_ARGS=--accept-license -p 8000:8000 -p 8089:8089 splunk/splunk start
139- * docker run -it -e SPLUNK_START_ARGS=--accept-license -e SPLUNK_LICENSE_URI=http://example.com/splunk.lic -p 8000:8000 splunk/splunk start
140- * docker run -it -e SPLUNK_START_ARGS=--accept-license -e SPLUNK_INDEXER_URL=idx1,idx2 -e SPLUNK_SEARCH_HEAD_URL=sh1,sh2 -e SPLUNK_ROLE=splunk_search_head --hostname sh1 --network splunknet --network-alias sh1 -e SPLUNK_PASSWORD=helloworld -e SPLUNK_LICENSE_URI=http://example.com/splunk.lic splunk/splunk start
143+ * docker run -it -p 8000:8000 splunk/splunk start
144+ * docker run -it -e SPLUNK_START_ARGS=--accept-license -p 8000:8000 -p 8089:8089 splunk/splunk start
145+ * docker run -it -e SPLUNK_START_ARGS=--accept-license -e SPLUNK_LICENSE_URI=http://example.com/splunk.lic -p 8000:8000 splunk/splunk start
146+ * docker run -it -e SPLUNK_START_ARGS=--accept-license -e SPLUNK_INDEXER_URL=idx1,idx2 -e SPLUNK_SEARCH_HEAD_URL=sh1,sh2 -e SPLUNK_ROLE=splunk_search_head --hostname sh1 --network splunknet --network-alias sh1 -e SPLUNK_PASSWORD=helloworld -e SPLUNK_LICENSE_URI=http://example.com/splunk.lic splunk/splunk start
141147
142148EOF
143- exit 1
149+ exit 1
144150}
145151
146152case " $1 " in
@@ -157,12 +163,12 @@ case "$1" in
157163 configure_multisite $0
158164 ;;
159165 create-defaults)
160- create_defaults
161- ;;
166+ create_defaults
167+ ;;
162168 restart)
163- shift
164- restart $@
165- ;;
169+ shift
170+ restart $@
171+ ;;
166172 no-provision)
167173 user_permission_change
168174 tail -n 0 -f /etc/hosts &
0 commit comments