* i2prouter:

- Don't cd to script location, no longer required
    * RouterLaunch:
      - If no wrapper, put wrapper.log in system temp dir
        unless specified with -Dwrapper.logfile=/path/to/wrapper.log
        or it already exists in CWD (for backward compatibility)
      - Append rather than replace wrapper.log
      - Pass wrapper log location to router as a property, so that logs.jsp can find it
    * logs.jsp:
      - Get wrapper log location from a property too
    * runplain.sh:
      - Add path substitution to runplain.sh on install
      - Pass I2P base dir to the router as a property
    * wrapper.config:
      - Put wrapper.log in system temp dir for new installs
      - Pass I2P base dir to the router as a property
    * WorkingDir:
      - Don't migrate an existing install by default
      - Never migrate the data (too hard)
This commit is contained in:
zzz
2009-06-13 21:04:27 +00:00
parent 718375419e
commit 24daf00616
7 changed files with 94 additions and 64 deletions

View File

@ -17,16 +17,23 @@ public class LogsHelper extends HelperBase {
} }
public String getServiceLogs() { public String getServiceLogs() {
// look in new and old place // RouterLaunch puts the location here if no wrapper
File f = new File(_context.getLogDir(), "wrapper.log"); String path = System.getProperty("wrapper.logfile");
if (!f.exists()) File f;
f = new File(_context.getBaseDir(), "wrapper.log"); if (path != null) {
f = new File(path);
} else {
// look in new and old places
f = new File(System.getProperty("java.io.tmpdir"), "wrapper.log");
if (!f.exists())
f = new File(_context.getBaseDir(), "wrapper.log");
}
String str = FileUtil.readTextFile(f.getAbsolutePath(), 250, false); String str = FileUtil.readTextFile(f.getAbsolutePath(), 250, false);
if (str == null) if (str == null)
return ""; return "";
else { else {
str = str.replaceAll("<", "&lt;").replaceAll(">", "&gt;"); str = str.replaceAll("<", "&lt;").replaceAll(">", "&gt;");
return "<pre>" + str + "</pre>"; return "Location: " + f.getAbsolutePath() + "<pre>" + str + "</pre>";
} }
} }

View File

@ -52,7 +52,7 @@ public class WorkingDir {
* Only call this once on router invocation. * Only call this once on router invocation.
* Caller should store the return value for future reference. * Caller should store the return value for future reference.
*/ */
public static String getWorkingDir(boolean migrateOldData) { public static String getWorkingDir(boolean migrateOldConfig) {
String dir = System.getProperty(PROP_WORKING_DIR); String dir = System.getProperty(PROP_WORKING_DIR);
boolean isWindows = System.getProperty("os.name").startsWith("Win"); boolean isWindows = System.getProperty("os.name").startsWith("Win");
File dirf = null; File dirf = null;
@ -73,6 +73,18 @@ public class WorkingDir {
String cwd = System.getProperty(PROP_BASE_DIR); String cwd = System.getProperty(PROP_BASE_DIR);
if (cwd == null) if (cwd == null)
cwd = System.getProperty("user.dir"); cwd = System.getProperty("user.dir");
// Check for a hosts.txt file, if it exists then I2P is there
File oldDirf = new File(cwd);
File test = new File(oldDirf, "hosts.txt");
if (!test.exists()) {
System.err.println("ERROR - Cannot find I2P installation in " + cwd +
" - Will probably be just a router with no apps or console at all!");
// until we move reseeding from the console to the router, we
// won't be able to reseed, so we are probably doomed
return cwd;
}
// where we want to go // where we want to go
String rv = dirf.getAbsolutePath(); String rv = dirf.getAbsolutePath();
if (dirf.exists()) { if (dirf.exists()) {
@ -86,19 +98,19 @@ public class WorkingDir {
return cwd; return cwd;
} }
// Check for a hosts.txt file, if it exists then I2P is there // Check for a router.keys file or logs dir, if either exists it's an old install,
File oldDirf = new File(cwd);
File test = new File(oldDirf, "hosts.txt");
if (!test.exists()) {
System.err.println("ERROR - Cannot find I2P installation in " + cwd);
return cwd;
}
// Check for a router.keys file, if it exists it's an old install,
// and only migrate the data files if told to do so // and only migrate the data files if told to do so
// (router.keys could be deleted later by a killkeys())
test = new File(oldDirf, "router.keys"); test = new File(oldDirf, "router.keys");
boolean oldInstall = test.exists(); boolean oldInstall = test.exists();
migrateOldData &= oldInstall; if (!oldInstall) {
test = new File(oldDirf, "logs");
oldInstall = test.exists();
}
// keep everything where it is, in one place...
if (oldInstall && !migrateOldConfig)
return cwd;
boolean migrateOldData = false; // this is a terrible idea
// Do the copying // Do the copying
if (migrateOldData) if (migrateOldData)

View File

@ -109,6 +109,7 @@
<parsable targetfile="$INSTALL_PATH/wrapper.config" type="javaprop" /> <parsable targetfile="$INSTALL_PATH/wrapper.config" type="javaprop" />
<parsable targetfile="$INSTALL_PATH/i2prouter" type="shell" os="unix|mac" /> <parsable targetfile="$INSTALL_PATH/i2prouter" type="shell" os="unix|mac" />
<parsable targetfile="$INSTALL_PATH/eepget" type="shell" os="unix|mac" /> <parsable targetfile="$INSTALL_PATH/eepget" type="shell" os="unix|mac" />
<parsable targetfile="$INSTALL_PATH/runplain.sh" type="shell" os="unix|mac" />
<!-- postinstall stuff for windows --> <!-- postinstall stuff for windows -->
<executable targetfile="$INSTALL_PATH/installer/copy.jar" type="jar" stage="postinstall" keep="true" failure="warn"> <os family="windows" /> <executable targetfile="$INSTALL_PATH/installer/copy.jar" type="jar" stage="postinstall" keep="true" failure="warn"> <os family="windows" />

View File

@ -8,28 +8,31 @@
# if you have changed the default location set in the # if you have changed the default location set in the
# wrapper configuration file. # wrapper configuration file.
# #
# Note that (percent)INSTALL_PATH and (percent)SYSTEM_java_io_tmpdir
# should have been replaced by
# the izpack installer. If you did not run the installer,
# replace them with the appropriate path.
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# These settings can be modified to fit the needs of your application # These settings can be modified to fit the needs of your application
# Paths
# Note that (percent)INSTALL_PATH and (percent)SYSTEM_java_io_tmpdir
# should have been replaced by the izpack installer.
# If you did not run the installer, replace them with the appropriate path.
I2P="%INSTALL_PATH"
I2PTEMP="%SYSTEM_java_io_tmpdir"
# Application # Application
APP_NAME="i2p" APP_NAME="i2p"
APP_LONG_NAME="I2P Service" APP_LONG_NAME="I2P Service"
# Wrapper # Wrapper
WRAPPER_CMD="%INSTALL_PATH/i2psvc" WRAPPER_CMD="$I2P/i2psvc"
WRAPPER_CONF="%INSTALL_PATH/wrapper.config" WRAPPER_CONF="$I2P/wrapper.config"
# Priority at which to run the wrapper. See "man nice" for valid priorities. # Priority at which to run the wrapper. See "man nice" for valid priorities.
# nice is only used if a priority is specified. # nice is only used if a priority is specified.
PRIORITY= PRIORITY=
# Location of the pid file. # Location of the pid file.
PIDDIR="%SYSTEM_java_io_tmpdir" PIDDIR="$I2PTEMP"
# If uncommented, causes the Wrapper to be shutdown using an anchor file. # If uncommented, causes the Wrapper to be shutdown using an anchor file.
# When launched with the 'start' command, it will also ignore all INT and # When launched with the 'start' command, it will also ignore all INT and
@ -51,40 +54,6 @@ PIDDIR="%SYSTEM_java_io_tmpdir"
# Do not modify anything beyond this point # Do not modify anything beyond this point
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Get the fully qualified path to the script
case $0 in
/*)
SCRIPT="$0"
;;
*)
PWD=`pwd`
SCRIPT="$PWD/$0"
;;
esac
# Change spaces to ":" so the tokens can be parsed.
SCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
# Get the real path to this script, resolving any symbolic links
TOKENS=`echo $SCRIPT | sed -e 's;/; ;g'`
REALPATH=
for C in $TOKENS; do
REALPATH="$REALPATH/$C"
while [ -h "$REALPATH" ] ; do
LS="`ls -ld "$REALPATH"`"
LINK="`expr "$LS" : '.*-> \(.*\)$'`"
if expr "$LINK" : '/.*' > /dev/null; then
REALPATH="$LINK"
else
REALPATH="`dirname "$REALPATH"`""/$LINK"
fi
done
done
# Change ":" chars back to spaces.
REALPATH=`echo $REALPATH | sed -e 's;:; ;g'`
# Change the current directory to the location of the script
cd "`dirname "$REALPATH"`"
# Process ID # Process ID
ANCHORFILE="$PIDDIR/$APP_NAME.anchor" ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
PIDFILE="$PIDDIR/$APP_NAME.pid" PIDFILE="$PIDDIR/$APP_NAME.pid"

View File

@ -5,9 +5,17 @@
# probably not enough for i2p. # probably not enough for i2p.
# You should really use the i2prouter script instead. # You should really use the i2prouter script instead.
# #
export CP=. ; for j in lib/* ; do export CP=$CP:$j ; done;
# Paths
# Note that (percent)INSTALL_PATH and (percent)SYSTEM_java_io_tmpdir
# should have been replaced by the izpack installer.
# If you did not run the installer, replace them with the appropriate path.
I2P="%INSTALL_PATH"
I2PTEMP="%SYSTEM_java_io_tmpdir"
export CP="$I2P" ; for j in "$I2P/lib/*" ; do export CP="$CP:$j" ; done;
JAVA=java JAVA=java
JAVAOPTS="-Djava.library.path=.:lib -DloggerFilenameOverride=logs/log-router-@.txt" JAVAOPTS="-Djava.library.path=$I2P:$I2P/lib -Di2p.dir.base=$I2P -DloggerFilenameOverride=logs/log-router-@.txt"
nohup $JAVA -cp $CP $JAVAOPTS net.i2p.router.RouterLaunch > /dev/null 2>&1 & nohup $JAVA -cp "$CP" $JAVAOPTS net.i2p.router.RouterLaunch > /dev/null 2>&1 &
echo $! > router.pid echo $! > "$I2PTEMP/router.pid"

View File

@ -51,11 +51,12 @@ wrapper.java.additional.1=-DloggerFilenameOverride=logs/log-router-@.txt
wrapper.java.additional.2=-Dorg.mortbay.http.Version.paranoid=true wrapper.java.additional.2=-Dorg.mortbay.http.Version.paranoid=true
wrapper.java.additional.3=-Dorg.mortbay.util.FileResource.checkAliases=false wrapper.java.additional.3=-Dorg.mortbay.util.FileResource.checkAliases=false
wrapper.java.additional.4=-Dorg.mortbay.xml.XmlParser.NotValidating=true wrapper.java.additional.4=-Dorg.mortbay.xml.XmlParser.NotValidating=true
wrapper.java.additional.5=-Di2p.dir.base=$INSTALL_PATH
# Uncomment this for better performance. # Uncomment this for better performance.
# If it doesn't work, server mode is not available in your JVM. # If it doesn't work, server mode is not available in your JVM.
# This may not be required if your machine is already "server-class". # This may not be required if your machine is already "server-class".
# See http://java.sun.com/j2se/1.5.0/docs/guide/vm/server-class.html # See http://java.sun.com/j2se/1.5.0/docs/guide/vm/server-class.html
#wrapper.java.additional.5=-server #wrapper.java.additional.6=-server
# Initial Java Heap Size (in MB) # Initial Java Heap Size (in MB)
#wrapper.java.initmemory=4 #wrapper.java.initmemory=4
@ -86,7 +87,13 @@ wrapper.console.format=PM
wrapper.console.loglevel=INFO wrapper.console.loglevel=INFO
# Log file to use for wrapper output logging. # Log file to use for wrapper output logging.
wrapper.logfile=wrapper.log # You may wish to change this on linux so the log is
# preserved across OS restarts.
# If you do change it, add the following line above to
# tell the router where to find the wrapper log
# (change X to the next available number)
# wrapper.java.additional.X=-Dwrapper.logfile=/path/to/wrapper.log
wrapper.logfile=$SYSTEM_java_io_tmpdir/wrapper.log
# Format of output for the log file. (See docs for formats) # Format of output for the log file. (See docs for formats)
wrapper.logfile.format=LPTM wrapper.logfile.format=LPTM

View File

@ -1,13 +1,39 @@
package net.i2p.router; package net.i2p.router;
import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream; import java.io.PrintStream;
/**
* This is the class called by the runplain.sh script on linux
* and the i2p.exe launcher on Windows.
* (i.e. no wrapper)
*
* If there is no -Dwrapper.log=/path/to/wrapper.log on the java command line
* to specify a log file, check for existence of wrapper.log in CWD,
* for backward compatibility in old installations (don't move it).
* Otherwise, use (system temp dir)/wrapper.log.
* Create if it doesn't exist, and append to it if it does.
* Put the location in the environment as an absolute path, so logs.jsp can find it.
*/
public class RouterLaunch { public class RouterLaunch {
private static final String PROP_WRAPPER_LOG = "wrapper.logfile";
private static final String DEFAULT_WRAPPER_LOG = "wrapper.log";
public static void main(String args[]) { public static void main(String args[]) {
String path = System.getProperty(PROP_WRAPPER_LOG);
File logfile;
if (path != null) {
logfile = new File(path);
} else {
logfile = new File(DEFAULT_WRAPPER_LOG);
if (!logfile.exists())
logfile = new File(System.getProperty("java.io.tmpdir"), DEFAULT_WRAPPER_LOG);
}
System.setProperty(PROP_WRAPPER_LOG, logfile.getAbsolutePath());
try { try {
System.setOut(new PrintStream(new FileOutputStream("wrapper.log"))); System.setOut(new PrintStream(new FileOutputStream(logfile, true)));
} catch (IOException ioe) { } catch (IOException ioe) {
ioe.printStackTrace(); ioe.printStackTrace();
} }