What shell command would you use to stop Cassandra started locally? Is there one that stops it without the PID? If no, what command can you use to get the PID in shell script?
CodePudding user response:
Please tailor to your individual situation, since you mentioned that C* is started locally.
However you can use something like this in your script:
#!/bin/bash
PID=$(cat /var/run/cassandra/cassandra.pid)
sudo kill -9 $PID
CodePudding user response:
If you started Cassandra without designating a file for the PID, then you'll have to do something tricky, like this:
ps -ef | grep cassandra | grep "jmx\.local\.port=7199" | awk '{print $2}'
96165
Basically you're using ps
to get the status of all processes, grep
ping for "cassandra", and then grep
ping for something very specific to the Cassandra process (like local JMX on port 7199). Then, if you pipe that all through awk
, you can pretty easily just pull the second space-delimited "column."
There's probably a more graceful way to do this, but it'll work.
Then, as a user with privileges to the cassandra process, you can just run a kill
on that PID. Or, you could encapsulate that all into one, single command:
kill $(ps -ef | grep cassandra | grep "jmx\.local\.port=7199" | awk '{print $2}')