Cassandra as a Service

From WikiOD

This topic describes how to start Apache Cassandra as a service in windows and linux platforms. Remember you also start Cassandra from bin directory by running the batch or shell script.

Linux[edit | edit source]

Create the /etc/init.d/cassandra startup script.

Edit the contents of the file:

#!/bin/sh
#
# chkconfig: - 80 45
# description: Starts and stops Cassandra
# update daemon path to point to the cassandra executable
DAEMON=<Cassandra installed directory>/bin/cassandra
start() {
        echo -n "Starting Cassandra... "
        $DAEMON -p /var/run/cassandra.pid
        echo "OK"
        return 0
}
stop() {
        echo -n "Stopping Cassandra... "
        kill $(cat /var/run/cassandra.pid)
        echo "OK"
        return 0
}
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        stop
        start
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
esac
exit $?

Make the file executable:

sudo chmod +x /etc/init.d/cassandra

Add the new service to the list:

sudo chkconfig --add cassandra

Now you can manage the service from the command line:

sudo /etc/init.d/cassandra start
sudo /etc/init.d/cassandra stop
sudo /etc/init.d/cassandra restart

Windows[edit | edit source]

Download the latest apache commons daemon from Apache Commons Project Distributions.

Extract the commons daemon in <Cassandra installed directory>\bin.

Rename the extracted folder as daemon.

Add <Cassandra installed directory> as CASSANDRA_HOME in windows environment variable.

Edit the cassandra.yaml file in <Cassandra installed directory>\conf and uncomment the data_file_directories, commitlog_directory, saved_cache_directory and set the absolute paths.

Edit cassandra.bat in <Cassandra installed directory>\bin and replace the value for the PATH_PRUNSRV as follows:

for 32 bit windows, set PATH_PRUNSRV=%CASSANDRA_HOME%\bin\daemon\
for 64 bit windows, set PATH_PRUNSRV=%CASSANDRA_HOME%\bin\daemon\amd64\

Edit cassandra.bat and configure SERVICE_JVM for required service name.

SERVICE_JVM="cassandra"

With administrator privileges, run cassandra.bat install from command prompt.

Credit:Stack_Overflow_Documentation