Snippets

Ryan Faircloth splunk initscript

Created by Ryan Faircloth
#!/bin/sh
#
# /etc/init.d/splunk
# init script for Splunk.
# generated by 'splunk enable boot-start'.
#
# chkconfig: 2345 90 60
# description: Splunk indexer service
#
# Disable THP
# Disable ULIMITS
# Drop to "splunk" user via SUDO SPL-144192

RETVAL=0
 
. /etc/init.d/functions
 
# disable hugepages
disable_huge() {
 echo "disabling huge page support"
 THP=`find /sys/kernel/mm/ -name transparent_hugepage -type d | tail -n 1`
 for SETTING in "enabled" "defrag";do
     if test -f ${THP}/${SETTING}; then
         echo never > ${THP}/${SETTING}
     fi
 done
}
 
 
# change ulimits
change_ulimit() {
  ulimit -Hn 65535
  ulimit -Sn 65535
  ulimit -Hu 20480
  ulimit -Su 20480
  ulimit -Hf unlimited
  ulimit -Sf unlimited
}
 
splunk_start() {
  echo Starting Splunk...
  su - ${USER} -c '"$SPLUNK_HOME/bin/splunk" start --no-prompt --answer-yes'
  RETVAL=$?
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/splunk
}
splunk_stop() {
  echo Stopping Splunk...
  su - ${USER} -c '"$SPLUNK_HOME/bin/splunk" stop'
  RETVAL=$?
  [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/splunk
}
splunk_restart() {
  echo Restarting Splunk...
  su - ${USER} -c '"$SPLUNK_HOME/bin/splunk" restart'
  RETVAL=$?
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/splunk
}
splunk_status() {
  echo Splunk status:
  su - ${USER} -c '"$SPLUNK_HOME/bin/splunk" status'
  RETVAL=$?
}
case "$1" in
start)
   disable_huge
   change_ulimit
   splunk_start
   ;;
stop)
   splunk_stop
   ;;
restart)
   disable_huge
   change_ulimit
   splunk_restart
   ;;
status)
   splunk_status
   ;;
esac
 
exit $RETVAL

Comments (0)