Skip to content

Commit 1595f16

Browse files
author
Mike Dickey
committed
More whitespace changes in splunk/splunk entrypoint.sh file to fix
ascii art formatting and finish indenting consistency. Merged in same changes for running as splunk user to universal forwarder Dockerfile and entrypoint.sh. Updated whitespace in universal forwarder entrypoint.sh to also use tables for consistency.
1 parent 3ca30d0 commit 1595f16

File tree

3 files changed

+61
-51
lines changed

3 files changed

+61
-51
lines changed

splunk/common-files/entrypoint.sh

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ watch_for_failure(){
5656
echo Ansible playbook complete, will begin streaming var/log/splunk/splunkd_stderr.log
5757
echo
5858
user_permission_change
59-
# Any crashes/errors while Splunk is running should get logged to splunkd_stderr.log and sent to the container's stdout
6059
if [ `whoami` != "${SPLUNK_USER}" ]; then
6160
RUN_AS_SPLUNK="sudo -u ${SPLUNK_USER}"
6261
fi
62+
# Any crashes/errors while Splunk is running should get logged to splunkd_stderr.log and sent to the container's stdout
6363
if [ -z "$SPLUNK_TAIL_FILE" ]; then
6464
${RUN_AS_SPLUNK} tail -n 0 -f ${SPLUNK_HOME}/var/log/splunk/splunkd_stderr.log &
6565
else
@@ -69,13 +69,13 @@ watch_for_failure(){
6969
}
7070

7171
create_defaults() {
72-
createdefaults.py
72+
createdefaults.py
7373
}
7474

7575
start_and_exit() {
7676
if [ -z "$SPLUNK_PASSWORD" ]
7777
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"
78+
echo "WARNING: No password ENV var. Stack may fail to provision if splunk.password is not set in ENV or a default.yml"
7979
fi
8080
sh -c "echo 'starting' > ${CONTAINER_ARTIFACT_DIR}/splunk-container.state"
8181
setup
@@ -111,42 +111,42 @@ user_permission_change(){
111111

112112
help() {
113113
cat << EOF
114-
____ _ _ __
114+
____ _ _ __
115115
/ ___| _ __ | |_ _ _ __ | | __ \ \\
116116
\___ \| '_ \| | | | | '_ \| |/ / \ \\
117-
___) | |_) | | |_| | | | | < / /
117+
___) | |_) | | |_| | | | | < / /
118118
|____/| .__/|_|\__,_|_| |_|_|\_\ /_/
119-
|_|
119+
|_|
120120
========================================
121121
122122
Environment Variables:
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
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
141141
142142
Examples:
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
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
147147
148148
EOF
149-
exit 1
149+
exit 1
150150
}
151151

152152
case "$1" in

uf/common-files/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,15 @@ RUN \
9090
&& groupadd -r ${ANSIBLE_GROUP} \
9191
&& useradd -r -m -g ${ANSIBLE_GROUP} ${ANSIBLE_USER} \
9292
&& usermod -aG sudo ${ANSIBLE_USER} \
93+
&& usermod -aG ${ANSIBLE_GROUP} ${SPLUNK_USER} \
9394
# Container Artifact Directory is a place for all artifacts and logs that are generated by the provisioning process. The directory is owned by the user "ansible".
9495
&& mkdir ${CONTAINER_ARTIFACT_DIR} \
95-
&& chown -R ${ANSIBLE_USER}:${ANSIBLE_GROUP} $CONTAINER_ARTIFACT_DIR \
96+
&& chown -R ${ANSIBLE_USER}:${ANSIBLE_GROUP} ${CONTAINER_ARTIFACT_DIR} \
97+
&& chmod -R 775 ${CONTAINER_ARTIFACT_DIR} \
9698
&& chmod -R 555 ${SPLUNK_ANSIBLE_HOME} \
99+
&& chgrp ${ANSIBLE_GROUP} ${SPLUNK_ANSIBLE_HOME} ${SPLUNK_ANSIBLE_HOME}/ansible.cfg \
100+
&& chmod 775 ${SPLUNK_ANSIBLE_HOME} \
101+
&& chmod 664 ${SPLUNK_ANSIBLE_HOME}/ansible.cfg \
97102
&& chmod 755 /sbin/entrypoint.sh /sbin/createdefaults.py /sbin/checkstate.sh
98103

99104
USER ${ANSIBLE_USER}

uf/common-files/entrypoint.sh

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ setup() {
2020
# Check if the user accepted the license
2121
if [[ "$SPLUNK_START_ARGS" != *"--accept-license"* ]]; then
2222
printf "License not accepted, please ensure the environment variable SPLUNK_START_ARGS contains the '--accept-license' flag\n"
23-
printf "For example: docker run -e SPLUNK_START_ARGS=--accept-license splunk/splunk\n\n"
24-
printf "For additional information and examples, see the help: docker run -it splunk/splunk help\n"
23+
printf "For example: docker run -e SPLUNK_START_ARGS=--accept-license splunk/universalforwarder\n\n"
24+
printf "For additional information and examples, see the help: docker run -it splunk/universalforwarder help\n"
2525
exit 1
2626
fi
2727
}
@@ -35,6 +35,9 @@ trap teardown SIGINT SIGTERM
3535

3636
prep_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
@@ -52,42 +55,44 @@ watch_for_failure(){
5255
echo Ansible playbook complete, will begin streaming var/log/splunk/splunkd_stderr.log
5356
echo
5457
user_permission_change
55-
# Any crashes/errors while Splunk is running should get logged to splunkd_stderr.log and sent to the container's stdout
58+
if [ `whoami` != "${SPLUNK_USER}" ]; then
59+
RUN_AS_SPLUNK="sudo -u ${SPLUNK_USER}"
60+
fi
5661
# Any crashes/errors while Splunk is running should get logged to splunkd_stderr.log and sent to the container's stdout
5762
if [ -z "$SPLUNK_TAIL_FILE" ]; then
58-
sudo -u ${SPLUNK_USER} tail -n 0 -f ${SPLUNK_HOME}/var/log/splunk/splunkd_stderr.log &
63+
${RUN_AS_SPLUNK} tail -n 0 -f ${SPLUNK_HOME}/var/log/splunk/splunkd_stderr.log &
5964
else
60-
sudo -u ${SPLUNK_USER} tail -n 0 -f ${SPLUNK_TAIL_FILE} &
65+
${RUN_AS_SPLUNK} tail -n 0 -f ${SPLUNK_TAIL_FILE} &
6166
fi
6267
wait
6368
}
6469

6570
create_defaults() {
66-
createdefaults.py
71+
createdefaults.py
6772
}
6873

6974
start_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
75+
if [ -z "$SPLUNK_PASSWORD" ]
76+
then
77+
echo "WARNING: No password ENV var. Stack may fail to provision if splunk.password is not set in ENV or a default.yml"
78+
fi
7479
sh -c "echo 'starting' > ${CONTAINER_ARTIFACT_DIR}/splunk-container.state"
7580
setup
76-
prep_ansible
81+
prep_ansible
7782
ansible-playbook $ANSIBLE_EXTRA_FLAGS -i inventory/environ.py site.yml
7883
}
7984

8085
start() {
81-
trap teardown EXIT
86+
trap teardown EXIT
8287
start_and_exit
83-
watch_for_failure
88+
watch_for_failure
8489
}
8590

8691
restart(){
8792
trap teardown EXIT
8893
sh -c "echo 'restarting' > ${CONTAINER_ARTIFACT_DIR}/splunk-container.state"
89-
prep_ansible
90-
${SPLUNK_HOME}/bin/splunk stop 2>/dev/null || true
94+
prep_ansible
95+
${SPLUNK_HOME}/bin/splunk stop 2>/dev/null || true
9196
ansible-playbook -i inventory/environ.py start.yml
9297
watch_for_failure
9398
}
@@ -123,7 +128,7 @@ Environment Variables:
123128
124129
125130
EOF
126-
exit 1
131+
exit 1
127132
}
128133

129134
case "$1" in
@@ -136,12 +141,12 @@ case "$1" in
136141
start_and_exit $@
137142
;;
138143
create-defaults)
139-
create_defaults
140-
;;
144+
create_defaults
145+
;;
141146
restart)
142-
shift
143-
restart $@
144-
;;
147+
shift
148+
restart $@
149+
;;
145150
no-provision)
146151
user_permission_change
147152
tail -n 0 -f /etc/hosts &

0 commit comments

Comments
 (0)