diff --git a/dist/src/main/bin/heritrix b/dist/src/main/bin/heritrix index 3175a1d9..5a4a67c1 100644 --- a/dist/src/main/bin/heritrix +++ b/dist/src/main/bin/heritrix @@ -114,7 +114,7 @@ startMessage="${HERITRIX_HOME}/heritrix_dmesg.log" # Remove any file that may have been left over from previous starts. if [ -f $startMessage ] then - rm -f $startmessage + rm -f $startMessage fi # Run heritrix as daemon. Redirect stdout and stderr to a file. # Print start message with date, java version, java opts, ulimit, and uname. @@ -139,7 +139,8 @@ then else CLASSPATH=${CP} nohup $JAVACMD -Dheritrix.home=${HERITRIX_HOME} \ -Djava.protocol.handler.pkgs=org.archive.net \ - -Dheritrix.out=${HERITRIX_OUT} ${JAVA_OPTS} ${JMX_OPTS} \ + -Dheritrix.out=${HERITRIX_OUT} -Dheritrix.dmesg=${startMessage} \ + ${JAVA_OPTS} ${JMX_OPTS} \ $CLASS_MAIN $@ >> ${stdouterrlog} 2>&1 & HERITRIX_PID=$! diff --git a/dist/src/main/bin/heritrix.cmd b/dist/src/main/bin/heritrix.cmd index ad5b1877..b3bd4f5d 100644 --- a/dist/src/main/bin/heritrix.cmd +++ b/dist/src/main/bin/heritrix.cmd @@ -153,7 +153,7 @@ if not "%1"=="BGR" ( ) else ( title Heritrix :: adding ">>%stdouterrlog% 2>&1" causes an access denied error as heritrix writes also to this file - %JAVACMD% "-Dheritrix.home=%HERITRIX_HOME%" -Djava.protocol.handler.pkgs=org.archive.net "-Dheritrix.out=%HERITRIX_OUT%" %JAVA_OPTS% %CLASS_MAIN% %HERITRIX_CMDLINE% + %JAVACMD% "-Dheritrix.home=%HERITRIX_HOME%" -Djava.protocol.handler.pkgs=org.archive.net "-Dheritrix.out=%HERITRIX_OUT%" "-Dheritrix.dmesg=%startMessage%" %JAVA_OPTS% %CLASS_MAIN% %HERITRIX_CMDLINE% if errorlevel 130 goto :end if errorlevel 1 echo.!ERRORLEVEL! >"%HERITRIX_HOME%\heritrix_launch_problems" pause diff --git a/engine/src/main/java/org/archive/crawler/Heritrix.java b/engine/src/main/java/org/archive/crawler/Heritrix.java index 93837cfb..99a59959 100644 --- a/engine/src/main/java/org/archive/crawler/Heritrix.java +++ b/engine/src/main/java/org/archive/crawler/Heritrix.java @@ -71,7 +71,9 @@ import org.restlet.security.MapVerifier; * stderr show on the console, this class prints usage or startup output * such as where the web UI can be found, etc., to a STARTLOG that the shell * script is waiting on. As soon as the shell script sees output in this file, - * it prints its content and breaks out of its wait. + * it prints its content and breaks out of its wait. The STARTLOG is only + * written if its path is given by the heritrix.dmesg system + * property. * See ${HERITRIX_HOME}/bin/heritrix. * *

Heritrix can also be embedded or launched by webapp initialization or @@ -106,12 +108,11 @@ public class Heritrix { /** * Heritrix start log file. * - * This file contains standard out produced by this main class for startup - * only. Used by heritrix shell script. Name here MUST match that in the - * bin/heritrix shell script. This is a DEPENDENCY the shell - * wrapper has on this here java heritrix. + * System property naming a file to receive a copy of standard out produced + * by this main class for startup only. Set by the bin/heritrix + * shell script when backgrounding heritrix. If unset, no file is written. */ - private static final String STARTLOG = "heritrix_dmesg.log"; + private static final String STARTLOG_PROPERTY = "heritrix.dmesg"; private enum AuthMode { DIGEST, BASIC; @@ -227,15 +228,19 @@ public class Heritrix { } - BufferedOutputStream startupOutStream = - new BufferedOutputStream( - new FileOutputStream( - new File(getHeritrixHome(), STARTLOG)),16384); - PrintStream startupOut = - new PrintStream( - new TeeOutputStream( - System.out, - startupOutStream)); + String startLog = System.getProperty(STARTLOG_PROPERTY); + BufferedOutputStream startupOutStream = null; + PrintStream startupOut = System.out; + if (startLog != null) { + startupOutStream = + new BufferedOutputStream( + new FileOutputStream(startLog),16384); + startupOut = + new PrintStream( + new TeeOutputStream( + System.out, + startupOutStream)); + } CommandLine cl = getCommandLine(startupOut, args); if (cl == null) return; @@ -448,7 +453,9 @@ public class Heritrix { } finally { startupOut.flush(); // stop writing to side startup file - startupOutStream.close(); + if (startupOutStream != null) { + startupOutStream.close(); + } System.out.println("Heritrix version: " + ArchiveUtils.VERSION); }