in priam/src/main/java/com/netflix/priam/health/CassandraMonitor.java [67:138]
public void execute() throws Exception {
try {
checkRequiredDirectories();
instanceState.setIsRequiredDirectoriesExist(true);
} catch (IllegalStateException e) {
instanceState.setIsRequiredDirectoriesExist(false);
}
Process process = null;
BufferedReader input = null;
try {
// This returns pid for the Cassandra process
// This needs to be sent as command list as "pipe" of results is not allowed. Also, do
// not try to change
// with pgrep as it has limitation of 4K command list (cassandra command can go upto 5-6
// KB as cassandra lists all the libraries in command.
final String[] cmd = {
"/bin/sh",
"-c",
"ps -ef |grep -v -P \"\\sgrep\\s\" | grep " + config.getCassProcessName()
};
process = Runtime.getRuntime().exec(cmd);
input = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line = input.readLine();
if (line != null) {
// Setting cassandra flag to true
instanceState.setCassandraProcessAlive(true);
isCassandraStarted.set(true);
NodeProbe bean = JMXNodeTool.instance(this.config);
instanceState.setIsGossipActive(bean.isGossipRunning());
instanceState.setIsNativeTransportActive(bean.isNativeTransportRunning());
instanceState.setIsThriftActive(
bean.isThriftServerRunning() && thriftChecker.isThriftServerListening());
} else {
// Setting cassandra flag to false
instanceState.setCassandraProcessAlive(false);
isCassandraStarted.set(false);
}
} catch (Exception e) {
logger.warn("Exception thrown while checking if Cassandra is running or not ", e);
instanceState.setCassandraProcessAlive(false);
isCassandraStarted.set(false);
} finally {
if (process != null) {
IOUtils.closeQuietly(process.getInputStream());
IOUtils.closeQuietly(process.getOutputStream());
IOUtils.closeQuietly(process.getErrorStream());
}
if (input != null) IOUtils.closeQuietly(input);
}
try {
int rate = config.getRemediateDeadCassandraRate();
if (rate >= 0 && !config.doesCassandraStartManually()) {
if (instanceState.shouldCassandraBeAlive()
&& !instanceState.isCassandraProcessAlive()) {
long msNow = System.currentTimeMillis();
if (rate == 0
|| ((instanceState.getLastAttemptedStartTime() + rate * 1000)
< msNow)) {
cassMonitorMetrics.incCassAutoStart();
cassProcess.start(true);
instanceState.markLastAttemptedStartTime();
}
}
}
} catch (IOException e) {
logger.warn("Failed to remediate dead Cassandra", e);
}
}