123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: cassandra
- # Required-Start: $remote_fs $network $named $time
- # Required-Stop: $remote_fs $network $named $time
- # Should-Start: ntp mdadm
- # Should-Stop: ntp mdadm
- # 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 <[email protected]>
- DESC="Cassandra"
- NAME=cassandra
- PIDFILE=/var/run/$NAME/$NAME.pid
- SCRIPTNAME=/etc/init.d/$NAME
- CASSANDRA_CONF=/etc/cassandra
- WAIT_FOR_START=10
- CASSANDRA_HOME=/usr/share/cassandra
- CASSANDRA_LIB=$CASSANDRA_HOME
- CASSANDRA_PROG=/usr/sbin/cassandra
- FD_LIMIT=100000
- # Read configuration variable file if it is present
- [ -r /etc/default/$NAME ] && . /etc/default/$NAME
- valid_chome=`find $CASSANDRA_LIB/apache-cassandra*.jar 2> /dev/null`
- [ -n "$valid_chome" ] || exit 0
- [ -e $CASSANDRA_CONF/cassandra.yaml ] || exit 0
- [ -e $CASSANDRA_CONF/cassandra-env.sh ] || exit 0
- # Read Cassandra environment file.
- . $CASSANDRA_CONF/cassandra-env.sh
- if [ -z "$JVM_OPTS" ]; then
- echo "Initialization failed; \$JVM_OPTS not set!" >&2
- exit 3
- fi
- export JVM_OPTS
- # Export JAVA_HOME, if set.
- [ -n "$JAVA_HOME" ] && export JAVA_HOME
- # 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 0 if process is running, or nonzero if not.
- #
- # The nonzero value is 3 if the process is simply not running, and 1 if the
- # process is not running but the pidfile exists (to match the exit codes for
- # the "status" command; see LSB core spec 3.1, section 20.2)
- #
- CMD_PATT="cassandra.+CassandraDaemon"
- is_running()
- {
- if [ -f $PIDFILE ]; then
- pid=`cat $PIDFILE`
- grep -Eq "$CMD_PATT" "/proc/$pid/cmdline" 2>/dev/null && return 0
- return 1
- fi
- return 3
- }
- #
- # 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
- ulimit -l unlimited
- ulimit -n "$FD_LIMIT"
- cassandra_home=`getent passwd cassandra | awk -F ':' '{ print $6; }'`
- heap_dump_f="$cassandra_home/java_`date +%s`.hprof"
- error_log_f="$cassandra_home/hs_err_`date +%s`.log"
- [ -e `dirname "$PIDFILE"` ] || \
- install -d -ocassandra -gcassandra -m755 `dirname $PIDFILE`
- start-stop-daemon -S -c cassandra -a $CASSANDRA_PROG -q -p "$PIDFILE" -t >/dev/null || return 1
- start-stop-daemon -S -c cassandra -a $CASSANDRA_PROG -b -p "$PIDFILE" -- \
- -p "$PIDFILE" -H "$heap_dump_f" -E "$error_log_f" >/dev/null || return 2
- }
- #
- # 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
- start-stop-daemon -K -p "$PIDFILE" -R TERM/30/KILL/5 >/dev/null
- RET=$?
- rm -f "$PIDFILE"
- return $RET
- }
- 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
- ;;
- status)
- is_running
- stat=$?
- case "$stat" in
- 0) log_success_msg "$DESC is running" ;;
- 1) log_failure_msg "could not access pidfile for $DESC" ;;
- *) log_success_msg "$DESC is not running" ;;
- esac
- exit "$stat"
- ;;
- *)
- echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
- exit 3
- ;;
- esac
- :
- # vi:ai sw=4 ts=4 tw=0 et
|