Skip to content

Instantly share code, notes, and snippets.

@mlowicki
Created December 21, 2015 17:16
Show Gist options
  • Select an option

  • Save mlowicki/ba5181c97a93572bff26 to your computer and use it in GitHub Desktop.

Select an option

Save mlowicki/ba5181c97a93572bff26 to your computer and use it in GitHub Desktop.
#!/bin/sh
### BEGIN INIT INFO
# Provides: cassandra-reaper
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: cassandra-reaper daemon
# Description: This is a daemon that controls the cassandra-reaper
### END INIT INFO
# Author: Michal Lowicki <mlowicki@opera.com>
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="cassandra-reaper daemon"
NAME=cassandra-reaper
SCRIPTNAME=/etc/init.d/$NAME
DODTIME=5 # Time to wait for the server to die, in seconds
# If this value is set too low you might not
# let some servers to die gracefully and
# 'restart' will not work
PIDFILE=/var/run/$NAME/$NAME.pid
REAPER_HOME=/var/cassandra_reaper
JAR="${REAPER_HOME}/cassandra-reaper.jar"
# Read configuration variable file if it is present
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
. /lib/init/vars.sh
. /lib/lsb/init-functions
do_start() {
# Return
# 0 if daemon has been started
# 1 if daemon was already running
# 2 if daemon could not be started
[ -e `dirname "$PIDFILE"` ] || \
install -d -m755 `dirname $PIDFILE`
start-stop-daemon -S -p "$PIDFILE" -t --quiet \
--exec /usr/bin/java -- -jar "$JAR" server /etc/cassandra_reaper.yaml || return 1
start-stop-daemon -S -b --make-pidfile -p "$PIDFILE" --quiet \
--exec /usr/bin/java -- -jar "$JAR" server /etc/cassandra_reaper.yaml || return 2
}
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"
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)
[ -n "$DODTIME" ] && sleep $DODTIME
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)
status_of_proc -p $PIDFILE "" "$DESC"
exit $?
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
exit 3
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment