mirror of https://github.com/apache/cassandra
156 lines
3.6 KiB
Bash
156 lines
3.6 KiB
Bash
#! /bin/sh
|
|
### BEGIN INIT INFO
|
|
# Provides: cassandra
|
|
# Required-Start: $remote_fs
|
|
# Required-Stop: $remote_fs
|
|
# Default-Start: 2 3 4 5
|
|
# Default-Stop: 0 1 6
|
|
# Short-Description: distributed storage system for structured data
|
|
# Description: Cassandra is a distributed (peer-to-peer) system for
|
|
# the management and storage of structured data.
|
|
### END INIT INFO
|
|
|
|
# Author: Eric Evans <eevans@racklabs.com>
|
|
|
|
DESC="Cassandra"
|
|
NAME=cassandra
|
|
PIDFILE=/var/run/$NAME.pid
|
|
SCRIPTNAME=/etc/init.d/$NAME
|
|
CONFDIR=/etc/cassandra
|
|
JAVA_HOME="/usr/lib/jvm/java-6-openjdk/jre"
|
|
JSVC=/usr/bin/jsvc
|
|
JVM_MAX_MEM="1G"
|
|
JVM_START_MEM="128M"
|
|
|
|
[ -e /usr/share/cassandra/apache-cassandra.jar ] || exit 0
|
|
[ -e /etc/cassandra/storage-conf.xml ] || exit 0
|
|
|
|
# Read configuration variable file if it is present
|
|
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
|
|
|
|
# Load the VERBOSE setting and other rcS variables
|
|
. /lib/init/vars.sh
|
|
|
|
# Define LSB log_* functions.
|
|
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
|
|
. /lib/lsb/init-functions
|
|
|
|
#
|
|
# Function that returns the applications classpath
|
|
#
|
|
classpath()
|
|
{
|
|
cp=
|
|
for j in /usr/share/$NAME/*.jar; do
|
|
[ "x$cp" = "x" ] && cp=$j || cp=$cp:$j
|
|
done
|
|
|
|
# Include the conf directory for purposes of log4j.properties, and
|
|
# commons-daemon in support of the daemonization class.
|
|
printf "$cp:$CONFDIR:/usr/share/java/commons-daemon.jar"
|
|
}
|
|
|
|
#
|
|
# Function that returns 0 if process is running, 1 if not
|
|
#
|
|
is_running()
|
|
{
|
|
if [ -f $PIDFILE ]; then
|
|
if ps -p `cat $PIDFILE` &> /dev/null; then
|
|
return 0
|
|
fi
|
|
fi
|
|
return 1
|
|
}
|
|
|
|
#
|
|
# Function that starts the daemon/service
|
|
#
|
|
do_start()
|
|
{
|
|
# Return
|
|
# 0 if daemon has been started
|
|
# 1 if daemon was already running
|
|
# 2 if daemon could not be started
|
|
is_running && return 1
|
|
|
|
$JSVC \
|
|
-home $JAVA_HOME \
|
|
-pidfile $PIDFILE \
|
|
-errfile "&1" \
|
|
-outfile /var/log/$NAME/output.log \
|
|
-cp `classpath` \
|
|
-Xmx$JVM_MAX_MEM \
|
|
-Xms$JVM_START_MEM \
|
|
-Dcassandra \
|
|
-Dstorage-config=$CONFDIR \
|
|
-Dcom.sun.management.jmxremote.port=8080 \
|
|
-Dcom.sun.management.jmxremote.ssl=false \
|
|
-Dcom.sun.management.jmxremote.authenticate=false \
|
|
$JVM_EXTRA_OPTS \
|
|
org.apache.cassandra.thrift.CassandraDaemon
|
|
|
|
if ! is_running; then return 2; fi
|
|
}
|
|
|
|
#
|
|
# Function that stops the daemon/service
|
|
#
|
|
do_stop()
|
|
{
|
|
# Return
|
|
# 0 if daemon has been stopped
|
|
# 1 if daemon was already stopped
|
|
# 2 if daemon could not be stopped
|
|
# other if a failure occurred
|
|
is_running || return 1
|
|
$JSVC -stop -home $JAVA_HOME -pidfile $PIDFILE \
|
|
org.apache.cassandra.thrift.CassandraDaemon
|
|
is_running && return 2 || return 0
|
|
}
|
|
|
|
case "$1" in
|
|
start)
|
|
[ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
|
|
do_start
|
|
case "$?" in
|
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
esac
|
|
;;
|
|
stop)
|
|
[ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
|
|
do_stop
|
|
case "$?" in
|
|
0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
|
|
2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
|
|
esac
|
|
;;
|
|
restart|force-reload)
|
|
log_daemon_msg "Restarting $DESC" "$NAME"
|
|
do_stop
|
|
case "$?" in
|
|
0|1)
|
|
do_start
|
|
case "$?" in
|
|
0) log_end_msg 0 ;;
|
|
1) log_end_msg 1 ;; # Old process is still running
|
|
*) log_end_msg 1 ;; # Failed to start
|
|
esac
|
|
;;
|
|
*)
|
|
# Failed to stop
|
|
log_end_msg 1
|
|
;;
|
|
esac
|
|
;;
|
|
*)
|
|
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
|
|
exit 3
|
|
;;
|
|
esac
|
|
|
|
:
|
|
|
|
# vi:ai sw=4 ts=4 tw=0 et
|