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:

# 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/
        echo "OK"
        return 0
stop() {
        echo -n "Stopping Cassandra... "
        kill $(cat /var/run/
        echo "OK"
        return 0
case "$1" in
        echo $"Usage: $0 {start|stop|restart}"
        exit 1
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.


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