Last active
August 29, 2015 14:10
-
-
Save ianmariano/e4b8e050c4dc487e0bf5 to your computer and use it in GitHub Desktop.
Firing up Cassandra, OpsCenter and a DataAgent locally on OS X for development. This has some presumptions like the install locations (change to suit your purposes). This also presumes these services have already been configured and run properly without resorting to this script. Add to your path and chmod a+x it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CASSANDRA_HOME=/opt/apache/cassandra | |
OPSCENTER_HOME=/opt/apache/opscenter | |
CASS_LOG_DIR=$CASSANDRA_HOME/logs | |
CASS_LOGFILE=$CASS_LOG_DIR/system.log | |
CASS_PIDFILE=$CASSANDRA_HOME/cassandra.pid | |
OPSCENTER_LOGFILE=$CASS_LOG_DIR/opscenter.log | |
start_service() { | |
if [ ! -e $CASS_LOG_DIR ]; then | |
mkdir -v $CASS_LOG_DIR; | |
fi | |
echo -n Starting Cassandra... | |
if [ -e $CASS_LOGFILE ]; then | |
mv $CASS_LOGFILE $CASS_LOGFILE.`date "+%Y%m%d-%H%M%S"` | |
fi | |
$CASSANDRA_HOME/bin/cassandra -p $CASS_PIDFILE > $CASS_LOGFILE 2>&1 | |
echo OK | |
echo -n Starting agent... | |
$OPSCENTER_HOME/agent/bin/datastax-agent | |
echo OK | |
if [ -e $OPSCENTER_LOGFILE ]; then | |
mv $OPSCENTER_LOGFILE $OPSCENTER_LOGFILE.`date "+%Y%m%d-%H%M%S"` | |
fi | |
echo -n Starting OpsCenter... | |
$OPSCENTER_HOME/bin/opscenter > $OPSCENTER_LOGFILE 2>&1 & | |
echo OK | |
} | |
stop_service() { | |
opc_pid=`pgrep -u $USER -f start_opscenter` | |
if [ ! -z "$opc_pid" ]; then | |
echo Stopping OpsCenter. | |
kill -9 $opc_pid | |
fi | |
a_pid=`pgrep -u $USER -f datastax` | |
if [ ! -z "$a_pid" ]; then | |
echo Stopping agent. | |
kill -9 $a_pid | |
fi | |
cass_pid="" | |
if [ -e $CASS_PIDFILE ]; then | |
cass_pid=`cat $CASS_PIDFILE` | |
fi | |
if [ ! -z "$cass_pid" ]; then | |
echo Stopping Cassandra | |
kill $cass_pid | |
rm -f $CASS_PIDFILE | |
fi | |
} | |
service_status() { | |
if [ -e $CASS_PIDFILE ]; then | |
echo Cassandra is running PID `cat $CASS_PIDFILE`. | |
else | |
echo Cassandra is not running. | |
fi | |
pid=`pgrep -u $USER -f datastax` | |
if [ -z "$pid" ]; then | |
echo Agent is not running. | |
else | |
echo Agent is running PID $pid. | |
fi | |
pid=`pgrep -u $USER -f start_opscenter` | |
if [ -z "$pid" ]; then | |
echo OpsCenter is not running. | |
else | |
echo OpsCenter is running PID $pid. | |
fi | |
} | |
usage() { | |
echo " | |
cassandra-service usage: | |
cassandra-service start|stop|status | |
" | |
exit 1 | |
} | |
if [ -z "$1" ]; then | |
usage | |
fi | |
set -e | |
case "$1" in | |
start) | |
start_service | |
;; | |
stop) | |
stop_service | |
;; | |
status) | |
service_status | |
;; | |
*) | |
echo Unknown command \"$1\" | |
usage | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment