From 43ed1aa320460f77ae18261dd29ede2d6fe629e2 Mon Sep 17 00:00:00 2001 From: kytv Date: Tue, 21 Jun 2011 22:45:21 +0000 Subject: [PATCH] Make i2prouter fail more gracefully if the wrapper cannot be loaded (either wrong architecture or i2psvc is just plain missing) and give a more useful error message. --- history.txt | 4 ++ installer/resources/i2prouter | 70 ++++++++++++++++++++++++++++++----- 2 files changed, 65 insertions(+), 9 deletions(-) diff --git a/history.txt b/history.txt index bd5d4949d7..ae58bf85f2 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,7 @@ +2011-06-21 kytv + * Make the i2prouter script fail more gracefully if there's + a problem loading the wrapper. + 2011-06-14 zzz * Build: New targets for including jbigi in the updater * Console: CSS tweak for flag box diff --git a/installer/resources/i2prouter b/installer/resources/i2prouter index be6ef4fcd4..44267d8f49 100644 --- a/installer/resources/i2prouter +++ b/installer/resources/i2prouter @@ -28,6 +28,8 @@ I2PTEMP="%SYSTEM_java_io_tmpdir" # Use the following instead. #I2PTEMP="%INSTALL_PATH" +WRAPPER_URL="http://www.i2p2.de/manualwrapper" + # Application APP_NAME="i2p" APP_LONG_NAME="I2P Service" @@ -36,6 +38,26 @@ APP_LONG_NAME="I2P Service" WRAPPER_CMD="$I2P/i2psvc" WRAPPER_CONF="$I2P/wrapper.config" +unsupported() { + echo "The most likely reason is that a supported version of the java" + echo "wrapper is not available in the I2P installation package for your" + echo "platform. It may be possible to manually download and install" + echo "a compatible wrapper for your system." + echo "See ${WRAPPER_URL} for hints." + echo + echo "In the meantime, you may start I2P by running the script" + echo "${I2P}/runplain.sh" + echo +} + +if [ ! -r ${WRAPPER_CMD} ]; then + echo "Unable to locate i2psvc in ${I2P}!" + echo + unsupported + echo + exit 1 +fi + # Priority at which to run the wrapper. See "man nice" for valid priorities. # nice is only used if a priority is specified. PRIORITY= @@ -133,15 +155,16 @@ testpid() { } console() { - echo "Running $APP_LONG_NAME..." + echo -n "Running $APP_LONG_NAME..." getpid if [ "X$pid" = "X" ] then if [ "X$IGNORE_SIGNALS" = "X" ] then - exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE + trap "exit 1" INT + (exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE 2> /dev/null ) || failed else - exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE + (exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE 2> /dev/null) || failed fi else echo "$APP_LONG_NAME is already running." @@ -150,30 +173,34 @@ console() { } start() { - echo "Starting $APP_LONG_NAME..." + echo -n "Starting $APP_LONG_NAME..." getpid if [ "X$pid" = "X" ] then if [ "X$IGNORE_SIGNALS" = "X" ] then - if [ "X$RUN_AS_USER" = "X" ] + if [ "X$RUN_AS_USER" = "X" ] then - exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.daemonize=TRUE + (exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.daemonize=TRUE > /dev/null 2>&1) || failed else - su -m $RUN_AS_USER -c "exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.daemonize=TRUE" + (su -m $RUN_AS_USER -c "exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE \ + wrapper.daemonize=TRUE" > /dev/null 2>&1) || failed fi else if [ "X$RUN_AS_USER" = "X" ] then - exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE wrapper.ignore_signals=TRUE wrapper.daemonize=TRUE + (exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE \ + wrapper.ignore_signals=TRUE wrapper.daemonize=TRUE > /dev/null 2>&1) || failed else - su -m $RUN_AS_USER -c "exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE wrapper.ignore_signals=TRUE wrapper.daemonize=TRUE" + (su -m $RUN_AS_USER -c "exec $CMDNICE $WRAPPER_CMD $WRAPPER_CONF i2psvc.pidfile=$PIDFILE wrapper.anchorfile=$ANCHORFILE \ + wrapper.ignore_signals=TRUE wrapper.daemonize=TRUE" > /dev/null 2>&1) || failed fi fi else echo "$APP_LONG_NAME is already running." exit 1 fi + echo "done." } stopit() { @@ -284,6 +311,30 @@ dump() { fi } +failed() { + echo "**Failed to load the wrapper**" + case `uname -s` in + FreeBSD) + echo + echo "In an attempt to ensure that I2P will run on as many systems as possible, included in the" + echo "installation package is a version of the wrapper that was compiled for FreeBSD 6." + echo "Necessary compatibility libraries may not be on your system." + echo + echo "Please install the misc/compat6x port and try running I2P again." + echo + echo "If you cannot (or choose not to) install these libraries, I2P may be started with the" + echo "'runplain.sh' script. Another option would be to compile the java wrapper for your system." + echo "Hints to accomplish this can be found at ${WRAPPER_URL}." + echo + exit 1 + ;; + *) + echo + unsupported + exit 1 + ;; + esac +} case "$1" in 'console') @@ -300,6 +351,7 @@ case "$1" in 'restart') stopit + sleep 2 start ;;