Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #28 Add Windows Support #34

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,11 @@ hs_err_pid*
cachefile

# PMD
.pmd
.pmd
*.bak
farsandra-core/ivy.xml
farsandra-core/src/test/ivy.xml
farsandra-core/src/test/bin/farsandra.properties
farsandra-core/src/test/bin/farsandra_custom.properties
farsandra-core/src/test/bin/log4j.xml
farsandra-core/src/test/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CForgroundManager {

private static Logger LOGGER = Logger.getLogger(CForgroundManager.class);
private String [] launchArray;
private String [] envArray = null;
private Process process;
/**
* The exit value of the forked process. Initialized to 9999.
Expand Down Expand Up @@ -51,6 +52,16 @@ public void setLaunchArray(String[] launchArray) {
}


/**
* Set the fork command environment variables

* @param envArray
*/
public void setEvnArray(String[] envArray) {
this.envArray = envArray;
}


/**
* Add a handler for system out events

Expand Down Expand Up @@ -86,10 +97,20 @@ public void go() {
* String launch = "/bin/bash -c \"env - CASSANDRA_CONF=" + instanceConf.getAbsolutePath()
* +" JAVA_HOME="+ "/usr/java/jdk1.7.0_45 " + cstart.getAbsolutePath().toString() + " -f \"";
*/
LOGGER.debug(Arrays.asList(this.launchArray));
LOGGER.debug("LAUNCH COMANDS: " + Arrays.asList(this.launchArray));
if (this.envArray != null) {
LOGGER.debug("ENVIRONMENT: " + Arrays.asList(this.envArray));
}
Runtime rt = Runtime.getRuntime();
try {
process = rt.exec(launchArray);
if (envArray != null)
{
process = rt.exec(launchArray,envArray);
}
else
{
process = rt.exec(launchArray);
}
} catch (IOException e1) {
LOGGER.error(e1.getMessage());
throw new RuntimeException(e1);
Expand Down Expand Up @@ -125,11 +146,71 @@ public void run() {
errstreamThread.start();
}

public void windowsDestroy() {

// Unlike in unix killing a process does not kill any child processes.
// In order to destroy our Cassandra java process, we'll use wimc to query
// for a java process with our instance name in the classpath.
String confPath = null;
for (String s : envArray)
{
if (s.contains("CASSANDRA_CONF")) {
confPath = s.split("=")[1];

// wimc requires paths to be double-quoted backslashes.
String wmicKill = "wmic PROCESS where " +
"\"" + "name like '%java%' and CommandLine like " +
"'%" + confPath.replace("\\", "\\\\") + "%' and " +
"CommandLine like '%CassandraDaemon%'" + "\"" +
" delete";
try {
Process p = Runtime.getRuntime().exec(wmicKill);
p.getOutputStream().close();
p.waitFor();
int exitCode = p.exitValue();
if (exitCode == 0) {
LOGGER.info("Cassandra process destroyed.");
}else {
LOGGER.error("Non-zero exit code from killing the cassandra process.");
}

} catch (IOException | InterruptedException e) {
LOGGER.error("Could not kill the Cassandra java child process");
}
break;
}
}
if (confPath == null) {
LOGGER.error("Could not locate and kill java child process");
}
process.destroy();
try {
process.waitFor();
} catch (InterruptedException e) {
; // nothing to do
}
}

/**
* End the process but do not wait for shutdown latch. Non blocking
*/
public void destroy(){
process.destroy();
if (isWindows()) {
windowsDestroy();
} else {
process.destroy();
}
}

/**
* Determines if the operating system is Windows
*
* @return a boolean value indicating if we're on Windows OS
*/

private boolean isWindows() {
String os = System.getProperty("os.name");
return os.contains("Windows");
}

/**
Expand Down
Loading