Skip to content

Commit

Permalink
Recommit some of the fix for NAS-2435
Browse files Browse the repository at this point in the history
  • Loading branch information
svcarlsen committed Aug 14, 2015
1 parent 135c480 commit 9a7fd21
Showing 1 changed file with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,8 @@ public abstract class AbstractRestHeritrixController implements IHeritrixControl
/** The port to use for Heritrix GUI, as set in settings.xml. */
private final int guiPort = Settings.getInt(Heritrix3Settings.HERITRIX_GUI_PORT);

/**
* The shutdownHook that takes care of killing our process. This is removed in cleanup() when the process is shut
* down.
*/
private Thread processKillerHook;

/**
* Create a BnfHeritrixController object.
* Create a AbstractRestHeritrixController object.
*
* @param files Files that are used to set up Heritrix.
*/
Expand All @@ -83,7 +77,6 @@ public AbstractRestHeritrixController(Heritrix3Files files) {
SystemUtils.checkPortNotUsed(guiPort);

hostName = SystemUtils.getLocalHostName();
//hostName = SystemUtils.getLocalIP();
try {
log.info("Starting Heritrix for {} in crawldir {}", this, files.getCrawlDir());
String zipFileStr = files.getHeritrixZip().getAbsolutePath();
Expand Down Expand Up @@ -123,7 +116,6 @@ public AbstractRestHeritrixController(Heritrix3Files files) {
String[] cmd = {
"./bin/heritrix",
"-b",
//getHostName(),
hostName,
"-p ",
Integer.toString(guiPort),
Expand All @@ -143,7 +135,7 @@ public AbstractRestHeritrixController(Heritrix3Files files) {
if ((jvmOptsStr != null) && (!jvmOptsStr.isEmpty())) {
javaOpts = " " + jvmOptsStr;
}
String javaOptsValue = "-Xmx" + Settings.get(Heritrix3Settings.HERITRIX_HEAP_SIZE) + " " + javaOpts;
String javaOptsValue = "-Xmx" + Settings.get(Heritrix3Settings.HERITRIX_HEAP_SIZE) + " " + javaOpts + " " + getSettingsProperty();
h3launcher.env.put("JAVA_OPTS", javaOptsValue);
log.info(".. and setting JAVA_OPTS to '{}'", javaOptsValue);
String heritrixOutValue = files.getHeritrixOutput().getAbsolutePath();
Expand All @@ -153,13 +145,13 @@ public AbstractRestHeritrixController(Heritrix3Files files) {
outputPrinter = new PrintWriter(files.getHeritrixStdoutLog(), "UTF-8");
errorPrinter = new PrintWriter(files.getHeritrixStderrLog(), "UTF-8");
h3handler = new LaunchResultHandler(outputPrinter, errorPrinter);
log.info("..using the following environment settings: ");
h3launcher.start(h3handler);
Runtime.getRuntime().addShutdownHook(new HeritrixKiller());
log.info("Heritrix3 launched successfully");
} catch( Throwable e) {
log.debug("Unexpected error while launching H3: ", e);
throw new IOFailure("Unexpected error while launching H3: ", e);
String errMsg = "Unexpected error while launching H3: ";
log.debug(errMsg, e);
throw new IOFailure(errMsg, e);
}
}

Expand Down Expand Up @@ -196,6 +188,33 @@ public void closeError() {
}
}

/**
* @return the Settingsproperty for heritrix3
*/
private static String getSettingsProperty() {
StringBuilder settingProperty = new StringBuilder();
for (File file : Settings.getSettingsFiles()) {
settingProperty.append(File.pathSeparator);
String absolutePath = file.getAbsolutePath();
// check that the settings files not only exist but
// are readable
boolean readable = new File(absolutePath).canRead();
if (!readable) {
final String errMsg = "The file '" + absolutePath
+ "' is missing. ";
log.warn(errMsg);
throw new IOFailure("Failed to read file '" + absolutePath
+ "'");
}
settingProperty.append(absolutePath);
}
if (settingProperty.length() > 0) {
// delete last path-separator
settingProperty.deleteCharAt(0);
}
return "-Ddk.netarkivet.settings.file=" + settingProperty;
}

/**
* @return the HTTP port used by the Heritrix GUI.
*/
Expand Down

0 comments on commit 9a7fd21

Please sign in to comment.