How do I stop cassandra server running on a single node in my mac os x? Cassandra script doesn't have -stop option. Only way other than restart the mac os x, was to do a "ps" and find the java process which had arguments for cassandra and use kill -9 to kill the process.
But trying to restart cassandra after that still throws
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 7199; nested exception is:
java.net.BindException: Address already in use
.
Anybody seen it? Any quick solutions?
Following command is used to install Cassandra on MacOS. This installs Cassandra on location /usr/local/cellar/Cassandra . Following command is used to start Cassandra.
You can know the version from running cassandra by connecting it via CQLSH. The prompt displays the version of cassandra it connected to. Show activity on this post. Once you know the location of your Cassandra instance(s) you can simply execute the cassandra binary with the -v option.
If you've installed cassandra via homebrew, use brew info cassandra
and it will tell you how to load/unload cassandra using launchctl. This worked better for me than the other answers here.
Commands
brew info cassandra
To see status of cassandra
brew services start cassandra
To start cassandra
brew services stop cassandra
To stop cassandra
EDIT: I actually find this much more useful.
Open terminal and type:
$ ps -ax | grep cassandra
gives you a list of pids running with the name cassandra.
Use the PID number to kill the process for example here is a returned value: 708 ttys000 0:03.10 /usr/bin/java -ea -javaagent:Downloads/Web/Cassandra/dsc-cassandra-1.1.0/bin/
$ kill 708
Old post:
After posting my comment I found a stop-server script in the BIN.
You have to open up the script and comment out the code if you want to use that script. But here is what it says inside the script.
echo "please read the stop-server script before use"
# if you are using the cassandra start script with -p, this
# is the best way to stop:
kill `cat <pidfile>`
# otherwise, you can run something like this, but
# this is a shotgun approach and will kill other processes
# with cassandra in their name or arguments too:
# user=`whoami`
# pgrep -u $user -f cassandra | xargs kill -9
Found this solution elsewhere which seems to work!
pkill -f 'java.*cassandra'
Worth a try! This works on the Ubuntu I have. Not on MacOS!
On Mac one more is ps -af | grep cassandra
and then using kill. But, it does not work sometimes!
Another approach is to see which OS process has the Cassandra port open, like this:
lsof -i :9160
Sample output:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 30253 aswan 214u IPv4 0xffffff80190dcc20 0t0 TCP *:netlock1 (LISTEN)
Then you can use "kill -9 [pid]" on that process.
You can use Cassandra's nodetool command, as well.
nodetool drain
The documentation doesn't say anything about it shutting down, but it works reliably for me with a single node, local server. It generally takes a few seconds to finish the shutdown, however.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With