cookbooks/mu-splunk/templates/default/splunk-init.erb
#!/bin/sh
#
# /etc/init.d/splunk
# init script for Splunk.
# generated by 'splunk enable boot-start'.
#
### BEGIN INIT INFO
# Provides: splunkd
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start splunk
# Description: Splunk indexer service
### END INIT INFO
#
RETVAL=0
splunk_start() {
echo Starting Splunk...
<% if @runasroot %>
"<%= @splunkdir %>/bin/splunk" start --no-prompt --answer-yes
<% else %>
/bin/su - splunk -c "\"<%= @splunkdir %>/bin/splunk\" start --no-prompt --answer-yes"
<% end %>
RETVAL=$?
}
splunk_stop() {
echo Stopping Splunk...
<% if @runasroot %>
"<%= @splunkdir %>/bin/splunk" stop
<% else %>
/bin/su - splunk -c "\"<%= @splunkdir %>/bin/splunk\" stop "
<% end %>
RETVAL=$?
}
splunk_restart() {
echo Restarting Splunk...
<% if @runasroot %>
"<%= @splunkdir %>/bin/splunk" restart --no-prompt --answer-yes
<% else %>
/bin/su - splunk -c "\"<%= @splunkdir %>/bin/splunk\" restart --no-prompt --answer-yes"
<% end %>
RETVAL=$?
}
splunk_status() {
echo Splunk status:
<% if @runasroot %>
"<%= @splunkdir %>/bin/splunk" status --no-prompt --answer-yes
<% else %>
/bin/su - splunk -c "\"<%= @splunkdir %>/bin/splunk\" status --no-prompt --answer-yes"
<% end %>
RETVAL=$?
}
case "$1" in
start)
splunk_start
;;
stop)
splunk_stop
;;
restart)
splunk_restart
;;
status)
splunk_status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
exit $RETVAL