June 17th, 2010

Run Cassandra As A Windows Service

One of the main issues that comes up over and over again for Cassandra is:

How do I run Cassandra as a Windows Service?

In this post I am going to answer that question and in the process demonstrate how to do it in less than 10 minutes.

Background

Cassandra is mainly developed by Linux developers so very little attention has been paid to the Windows developer or administrator as far as Cassandra goes.  So as Windows developers we have to hop through a couple more hoops than just clicking on an install.exe file and and letting it do all the work.  However lucky for us, those hoops are easy and quickly hopped through.

Step 1

If you haven’t done so already please read my jump start for Windows users on install Cassandra, this guide will get you ready for the next steps.

Step 2

The second step is also an easy one, you need to download a package called RunAsService, which provides the ability to run any program as a Windows Service.

After you have downloaded the file extract the contents to a directory of your choosing.  (I extracted it to c:\RunAsService)

Note: RunAsService was originally developed here, however I recompiled it to run on .NET 2.0.

Step 3

To install RunAsService open up a command prompt with Administrative privileges and run this command.

cd c:\RunAsService
install networkservice

This registers RunAsService with your Windows Service.  Make sure to keep your command prompt open because you will need it for the 5th step.

Step 4

To configure RunAsService for Cassandra open up the RunAsService.exe.config file in your favorite text editor and replace <service.settings> section with the following so that it looks like this:

<!-- Services configuration -->
<service.settings>
    <!-- Run Cassandra as a service -->
    <!-- My Cassandra install path is C:\apache-cassandra\ -->
    <service>
        <name>Cassandra Database</name>
        <executable>C:\apache-cassandra\bin\cassandra.bat</executable>
        <parameters></parameters>
    </service>
</service.settings>

After you have finished, save the config file and exit your text editor.

Note: My Cassandra install is in c:\apache-cassandra\ you will have to correct the config above for where you installed it if different than mine.

Step 5

The last and final step of this process is to start the RunAsService service.  You can either do it through the Services control panel or just type the following in to your command prompt.

net start runasservice

You should see a response in the command line saying that the service has been successfully started.  To verify that Cassandra has been started you can use the cassandra-cli.bat file:

cd c:\apache-cassandra\bin\
cassandra-cli.bat
connect localhost/9160

It should report that it is connected to the server if the service is running.  And with that we are done, and I told you it would only take about 10 minutes.

Tags: ,

Social: kick it on DotNetKicks.com | Shout it | Add to DZone |

This entry was posted on Thursday, June 17th, 2010 at 11:16 am and is filed under How To. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

7 Responses to “Run Cassandra As A Windows Service”

  1. DotNetShoutout Says:

    Run Cassandra As A Windows Service – Nick Berardi’s Coder Journal…

    Thank you for submitting this cool story – Trackback from DotNetShoutout…

  2. Mark Says:

    Hi -

    Thanks for this. I got stuck at Step 3 through.

    The zip that you’ve given to download doesn’t have the install.cmd at the top level.

    I eventually copied it from SetupRunAsService into RunAsService/bin/Release, where it ran OK, and it looked like the network service was running with the config you describe, but then when I tried to connect I got

    Exception connecting to localhost/9160 – java.net.ConnectException: Connection r
    efused: connect

    Maybe this is a problem with my Cassandra config though and not related to setting up RunAsService?

    Your other article on ‘Jump Start for Windows’ was very helpful by the way… thanks.

    Mark

  3. Nick Berardi Says:

    Hi Mark,

    I have been working on laying out the RunAsService project a little better. It was an old .NET 1.1 project that I have been updating. See if the new version is a better fit.

    As for your error. It doesn’t sound like Cassandra is running. If all else fails, uninstall the service and then reinstall using the above steps.

    Nick

  4. Ronald Widha » Blog Archive » Resources on Apache Cassandra for the .Net devs Says:

    [...] Running Cassandra as a Windows service [...]

  5. sirmak Says:

    Hi
    Very helpful article, thank you and

    Can you compare fluentcassandra with cassandraemon
    In which conditions we have to choose one over other, is one them hava a coding superiority, etc…

    If fluentcassandra is better, is there some functionality or better code parts that can be taken from cassandraemon ?

    thanks

    sirmak

  6. Nick Berardi Says:

    Not the best person to reply on that. I developed Fluent Cassandra.

  7. JavierCanillas Says:

    I’m working with Cassandra in .NET Framework and I created a .NET framework called “Aquiles” that have some improvements from using Thrift code directly. Take a look at it. Any feedback will be appreciated.

Leave a Reply