Only write heritrix_dmesg.log when requested (#779)

Only write heritrix_dmesg.log when requested

Heritrix.java always created heritrix_dmesg.log in $HERITRIX_HOME, even
though only the bin/heritrix script reads it, and only when it starts
Heritrix in the background. This got in the way of making
$HERITRIX_HOME read-only for Docker and systemd setups.

The startup log is now written only when the heritrix.dmesg system
property gives its path. bin/heritrix sets this property in background
mode and keeps the file in the same place as before.

Also fix a typo in bin/heritrix ($startmessage) that stopped it
removing a heritrix_dmesg.log left over from a previous start.

Set -Dheritrix.dmesg in heritrix.cmd too.
This commit is contained in:
Alex Osborne authored and GitHub committed 2026-10-06 11:29:51 +09:00
1 parent 0ca9e5dc2a
commit a09f38570d
3 files changed
+27 -19

No files matched your search

+3 -2
View File
@@ -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=$!
+1 -1
View File
@@ -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
@@ -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 <code>heritrix.dmesg</code> system
* property.
* See ${HERITRIX_HOME}/bin/heritrix.
*
* <p>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
* <code>bin/heritrix</code> 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 <code>bin/heritrix</code>
* 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);
}