in cassandra-launcher/src/main/scala/org/apache/pekko/persistence/cassandra/testkit/CassandraLauncher.scala [319:373]
private def startForked(
configFile: File,
cassandraBundle: File,
classpath: immutable.Seq[String],
host: String,
port: Int): Unit = {
// Calculate classpath
val / = File.separator
val javaBin = s"${System.getProperty("java.home")}${/}bin${/}java"
val className = "org.apache.cassandra.service.CassandraDaemon"
val classpathArgument = (classpath :+ cassandraBundle.getAbsolutePath).mkString(File.pathSeparator)
val builder = new ProcessBuilder(
javaBin,
"-cp",
classpathArgument,
"-Dcassandra.config=file:" + configFile.getAbsoluteFile,
"-Dcassandra-foreground=true",
className).inheritIO()
val process = builder.start()
val shutdownHook = new Thread {
override def run(): Unit = {
process.destroyForcibly()
}
}
Runtime.getRuntime.addShutdownHook(shutdownHook)
// We wait for Cassandra to start listening before we return, since running in non fork mode will also not
// return until Cassandra has started listening.
waitForCassandraToListen(host, port)
cassandraDaemon = Some(new Closeable {
override def close(): Unit = {
process.destroy()
try {
Runtime.getRuntime.removeShutdownHook(shutdownHook)
} catch {
case _: IllegalStateException =>
// JVM is already shutting down
}
if (process.waitFor(ForcedShutdownTimeout.toMillis, TimeUnit.MILLISECONDS)) {
val exitStatus = process.exitValue()
// Java processes killed with SIGTERM may exit with a status of 143
if (exitStatus != 0 && exitStatus != 143) {
sys.error(s"Cassandra exited with non zero status: ${process.exitValue()}")
}
} else {
process.destroyForcibly()
sys.error(s"Cassandra process did not stop within $ForcedShutdownTimeout, killing.")
}
}
})
}