#!/bin/sh # # Splunk -- It's tasty. # # description: Splunk Log Indexer # probe: false # chkconfig: 345 85 1 PATH=/sbin:/bin:/usr/bin test -f /opt/splunk/bin/splunk || exit 0 if [ -f /lib/lsb/init-functions ] && ! [ -e /etc/redhat-release ]; then . /lib/lsb/init-functions else # int log_begin_message (char *message) log_begin_msg () { if [ -z "$1" ]; then return 1 fi if type usplash_write >/dev/null 2>&1; then usplash_write "TEXT $*" || true fi # Only do the fancy stuff if we have an appropriate terminal # and if /usr is already mounted TPUT=/usr/bin/tput EXPR=/usr/bin/expr if [ -x $TPUT ] && [ -x $EXPR ] && \ $TPUT xenl >/dev/null 2>&1 && \ $TPUT hpa 60 >/dev/null 2>&1; then COLS=`$TPUT cols` if [ -n "$COLS" ]; then COL=`$EXPR $COLS - 7` else COL=73 fi # We leave the cursor `hanging' about-to-wrap # (see terminfo(5) xenl, which is approximately right). # That way if the script prints anything then we will # be on the next line and not overwrite part of the message. # Previous versions of this code attempted to colour-code # the asterisk but this can't be done reliably because # in practice init scripts sometimes print messages even # when they succeed and we won't be able to reliably know # where the colourful asterisk ought to go. printf " * $* " # Enough trailing spaces for ` [fail]' to fit in; if the # message is too long it wraps here rather than later, # which is what we want. $TPUT hpa `$EXPR $COLS - 1` printf ' ' else echo " * $*" COL='' fi } # int log_end_message (int exitstatus) log_end_msg () { # If no arguments were passed, return [ -z "$1" ] && return 1 if type usplash_write >/dev/null 2>&1; then if [ $1 -eq 0 ]; then usplash_write "SUCCESS ok" || true else usplash_write "FAILURE failed" || true fi fi if [ "$COL" ]; then printf "\r" $TPUT hpa $COL if [ $1 -eq 0 ]; then echo "[ ok ]" else printf '[' $TPUT setaf 1 # red printf fail $TPUT op # normal echo ']' fi else if [ $1 -eq 0 ]; then echo " ...done." else echo " ...fail!" fi fi return $1 } log_success_msg () { if type usplash_write >/dev/null 2>&1; then usplash_write "STATUS $*" || true fi echo " * $@" } fi case "$1" in start) log_begin_msg "Starting Splunk..." /opt/splunk/bin/splunk start > /dev/null 2>&1 log_end_msg $? ;; restart) log_begin_msg "Restarting Splunk..." /opt/splunk/bin/splunk restart > /dev/null 2>&1 log_end_msg $? ;; stop) log_begin_msg "Stopping Splunk..." /opt/splunk/bin/splunk stop > /dev/null 2>&1 log_end_msg $? ;; *) log_success_msg "Usage: /etc/init.d/splunk-init {start|stop|restart}" exit 1 esac exit 0