Skip to content

Instantly share code, notes, and snippets.

@nikolavp
Created April 30, 2013 10:59
Show Gist options
  • Save nikolavp/5488026 to your computer and use it in GitHub Desktop.
Save nikolavp/5488026 to your computer and use it in GitHub Desktop.
Cassandra upstart job
description "Cassandra is a distributed (peer-to-peer) system for the management and storage of structured data."
author "[email protected]"
start on filesystem
stop on runlevel[016]
env NAME=cassandra
env PIDFILE=/var/run/$NAME.pid
env SCRIPTNAME=/etc/init.d/$NAME
env CONFDIR=/etc/cassandra
env JSVC=/usr/bin/jsvc
env WAIT_FOR_START=20
env CASSANDRA_HOME=/usr/share/cassandra
respawn
# if we have respawned once in the last 20 seconds then just stop.
respawn limit 2 20
setuid cassandra
setgid cassandra
console log
chdir /
limit nofile 100000 100000
limit memlock unlimited unlimited
pre-start script
[ -e /usr/share/cassandra/apache-cassandra.jar ] || exit 0
[ -e /etc/cassandra/cassandra.yaml ] || exit 0
[ -e /etc/cassandra/cassandra-env.sh ] || exit 0
end script
script
# Get variables from here please. Setuid cannot be told to do a new login
# as the specified user :(
. /etc/profile
cassandra_home=`getent passwd cassandra | awk -F ':' '{ print $6; }'`
[ -r /etc/default/$NAME ] && . /etc/default/$NAME
# Read Cassandra environment file.
. /etc/cassandra/cassandra-env.sh
# setup the classpath. TODO: Maybe we can reuse /usr/share/cassandra/cassandra.in.sh
CLASSPATH="$EXTRA_CLASSPATH"
for j in /usr/share/$NAME/lib/*.jar; do
[ "x$CLASSPATH" = "x" ] && CLASSPATH=$j || CLASSPATH=$CLASSPATH:$j
done
for j in /usr/share/$NAME/*.jar; do
[ "x$CLASSPATH" = "x" ] && CLASSPATH=$j || CLASSPATH=$CLASSPATH:$j
done
echo $CLASSPATH
echo
# use JNA if installed in standard location
[ -r /usr/share/java/jna.jar ] && CLASSPATH="$CLASSPATH:/usr/share/java/jna.jar"
# Include the conf directory for purposes of log4j-server.properties, and
# commons-daemon in support of the daemonization class.
CLASSPATH="$CLASSPATH:$CONFDIR:/usr/share/java/commons-daemon.jar"
# think if we really want the pidfile :?
#-pidfile $PIDFILE \
# -errfile "&1" \
# -outfile /var/log/$NAME/output.log \
java \
-cp $CLASSPATH \
-Dlog4j.configuration=log4j-server.properties \
-Dlog4j.defaultInitOverride=true \
-Dcassandra-foreground=yes \
-XX:HeapDumpPath="$cassandra_home/java_`date +%s`.hprof" \
-XX:ErrorFile="$cassandra_home/hs_err_`date +%s`.log" \
$JVM_OPTS \
org.apache.cassandra.service.CassandraDaemon >> /var/log/cassandra/output.log 2>&1
end script
post-start script
for tries in `seq $WAIT_FOR_START`; do
sleep 1
nodetool status && exit 0
done
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment