cassandra Cassandra as a Service Linux


Example

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

  2. 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 $?
    
  3. Make the file executable:

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

  4. Add the new service to the list:

    sudo chkconfig --add cassandra

  5. 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