File cassandra.init.suse of Package cassandra

#!/bin/bash
#
# /etc/init.d/cassandra
#
# Startup script for Cassandra
# 
# chkconfig: 2345 20 80
# description: Starts and stops Cassandra
#
### BEGIN INIT INFO
# Provides:         cassandra
# Required-Start:   $network $remote_fs
# Required-Stop:    $network $remote_fs
# Default-Start:    3 5
# Default-Stop:     0 1 2 6
# Short-Description: Cassandra Server
# Description: Start and Stop Cassandra
### END INIT INFO

NAME="cassandra"
export CASSANDRA_HOME=/usr/share/cassandra
export CASSANDRA_CONF=/etc/cassandra/conf
export CASSANDRA_INCLUDE=$CASSANDRA_HOME/cassandra.in.sh
export CASSANDRA_OWNR=cassandra
CASSANDRA_PROG=/usr/sbin/cassandra
CASSANDRA_LOG=/var/log/cassandra/cassandra.log
CASSANDRA_PID=/var/run/cassandra/cassandra.pid

test -x $CASSANDRA_HOME  || exit 5

# Read configuration variable file if it is present
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME

. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
# 
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.

function makePidDir() {
pidDir=$(dirname $CASSANDRA_PID)
    if [ ! -d $pidDir ]; then
        echo "$pidDir does not exist, createing"
        mkdir $pidDir
        chown $CASSANDRA_OWNR:$CASSANDRA_OWNR $pidDir
    fi
}

case "$1" in
    start)
        makePidDir
        echo -n "Starting Cassandra"
        su $CASSANDRA_OWNR -c "$CASSANDRA_PROG -p $CASSANDRA_PID" >> $CASSANDRA_LOG 2>&1

        # Remember status and be verbose
        rc_status -v
        ;;
    stop)
        # Cassandra shutdown
        echo -n "Shutting down Cassandra"
        su $CASSANDRA_OWNR -c "kill `cat $CASSANDRA_PID`"
        for t in `seq 40`; do $0 status > /dev/null 2>&1 && sleep 0.5 || break; done
        # Adding a sleep here to give jmx time to wind down (CASSANDRA-4483). Not ideal...
        # Adam Holmberg suggests this, but that would break if the jmx port is changed
        # for t in `seq 40`; do netstat -tnlp | grep "0.0.0.0:7199" > /dev/null 2>&1 && sleep 0.1 || break; done
        sleep 5
        rc_status -v
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    reload)
        ## Does not support reload:
        rc_failed 3
        rc_status -v
        ;;
    status)
        checkproc -p $CASSANDRA_PID cassandra
        
        # Remember status and be quiet
        rc_status
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|reload}"
        exit 1
esac
rc_exit
openSUSE Build Service is sponsored by