cassandra.init 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: cassandra
  4. # Required-Start: $remote_fs $network $named $time
  5. # Required-Stop: $remote_fs $network $named $time
  6. # Should-Start: ntp mdadm
  7. # Should-Stop: ntp mdadm
  8. # Default-Start: 2 3 4 5
  9. # Default-Stop: 0 1 6
  10. # Short-Description: distributed storage system for structured data
  11. # Description: Cassandra is a distributed (peer-to-peer) system for
  12. # the management and storage of structured data.
  13. ### END INIT INFO
  14. # Author: Eric Evans <[email protected]>
  15. DESC="Cassandra"
  16. NAME=cassandra
  17. PIDFILE=/var/run/$NAME/$NAME.pid
  18. SCRIPTNAME=/etc/init.d/$NAME
  19. CASSANDRA_CONF=/etc/cassandra
  20. WAIT_FOR_START=10
  21. CASSANDRA_HOME=/usr/share/cassandra
  22. CASSANDRA_LIB=$CASSANDRA_HOME
  23. CASSANDRA_PROG=/usr/sbin/cassandra
  24. FD_LIMIT=100000
  25. # Read configuration variable file if it is present
  26. [ -r /etc/default/$NAME ] && . /etc/default/$NAME
  27. valid_chome=`find $CASSANDRA_LIB/apache-cassandra*.jar 2> /dev/null`
  28. [ -n "$valid_chome" ] || exit 0
  29. [ -e $CASSANDRA_CONF/cassandra.yaml ] || exit 0
  30. [ -e $CASSANDRA_CONF/cassandra-env.sh ] || exit 0
  31. # Read Cassandra environment file.
  32. . $CASSANDRA_CONF/cassandra-env.sh
  33. if [ -z "$JVM_OPTS" ]; then
  34. echo "Initialization failed; \$JVM_OPTS not set!" >&2
  35. exit 3
  36. fi
  37. export JVM_OPTS
  38. # Export JAVA_HOME, if set.
  39. [ -n "$JAVA_HOME" ] && export JAVA_HOME
  40. # Load the VERBOSE setting and other rcS variables
  41. . /lib/init/vars.sh
  42. # Define LSB log_* functions.
  43. # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
  44. . /lib/lsb/init-functions
  45. #
  46. # Function that returns 0 if process is running, or nonzero if not.
  47. #
  48. # The nonzero value is 3 if the process is simply not running, and 1 if the
  49. # process is not running but the pidfile exists (to match the exit codes for
  50. # the "status" command; see LSB core spec 3.1, section 20.2)
  51. #
  52. CMD_PATT="cassandra.+CassandraDaemon"
  53. is_running()
  54. {
  55. if [ -f $PIDFILE ]; then
  56. pid=`cat $PIDFILE`
  57. grep -Eq "$CMD_PATT" "/proc/$pid/cmdline" 2>/dev/null && return 0
  58. return 1
  59. fi
  60. return 3
  61. }
  62. #
  63. # Function that starts the daemon/service
  64. #
  65. do_start()
  66. {
  67. # Return
  68. # 0 if daemon has been started
  69. # 1 if daemon was already running
  70. # 2 if daemon could not be started
  71. ulimit -l unlimited
  72. ulimit -n "$FD_LIMIT"
  73. cassandra_home=`getent passwd cassandra | awk -F ':' '{ print $6; }'`
  74. heap_dump_f="$cassandra_home/java_`date +%s`.hprof"
  75. error_log_f="$cassandra_home/hs_err_`date +%s`.log"
  76. [ -e `dirname "$PIDFILE"` ] || \
  77. install -d -ocassandra -gcassandra -m755 `dirname $PIDFILE`
  78. start-stop-daemon -S -c cassandra -a $CASSANDRA_PROG -q -p "$PIDFILE" -t >/dev/null || return 1
  79. start-stop-daemon -S -c cassandra -a $CASSANDRA_PROG -b -p "$PIDFILE" -- \
  80. -p "$PIDFILE" -H "$heap_dump_f" -E "$error_log_f" >/dev/null || return 2
  81. }
  82. #
  83. # Function that stops the daemon/service
  84. #
  85. do_stop()
  86. {
  87. # Return
  88. # 0 if daemon has been stopped
  89. # 1 if daemon was already stopped
  90. # 2 if daemon could not be stopped
  91. # other if a failure occurred
  92. start-stop-daemon -K -p "$PIDFILE" -R TERM/30/KILL/5 >/dev/null
  93. RET=$?
  94. rm -f "$PIDFILE"
  95. return $RET
  96. }
  97. case "$1" in
  98. start)
  99. [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
  100. do_start
  101. case "$?" in
  102. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  103. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  104. esac
  105. ;;
  106. stop)
  107. [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
  108. do_stop
  109. case "$?" in
  110. 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
  111. 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
  112. esac
  113. ;;
  114. restart|force-reload)
  115. log_daemon_msg "Restarting $DESC" "$NAME"
  116. do_stop
  117. case "$?" in
  118. 0|1)
  119. do_start
  120. case "$?" in
  121. 0) log_end_msg 0 ;;
  122. 1) log_end_msg 1 ;; # Old process is still running
  123. *) log_end_msg 1 ;; # Failed to start
  124. esac
  125. ;;
  126. *)
  127. # Failed to stop
  128. log_end_msg 1
  129. ;;
  130. esac
  131. ;;
  132. status)
  133. is_running
  134. stat=$?
  135. case "$stat" in
  136. 0) log_success_msg "$DESC is running" ;;
  137. 1) log_failure_msg "could not access pidfile for $DESC" ;;
  138. *) log_success_msg "$DESC is not running" ;;
  139. esac
  140. exit "$stat"
  141. ;;
  142. *)
  143. echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload|status}" >&2
  144. exit 3
  145. ;;
  146. esac
  147. :
  148. # vi:ai sw=4 ts=4 tw=0 et