diff --git a/apps/routerconsole/java/src/net/i2p/router/web/ShellService.java b/apps/routerconsole/java/src/net/i2p/router/web/ShellService.java index f8bc63227986ee16e48ffaf15d766c39c60daf85..084d1263c1d8960acf935816b903798419c76709 100644 --- a/apps/routerconsole/java/src/net/i2p/router/web/ShellService.java +++ b/apps/routerconsole/java/src/net/i2p/router/web/ShellService.java @@ -79,8 +79,8 @@ public class ShellService implements ClientApp { ArrayList<String> procArgs = trimArgs(args); if (_log.shouldLog(Log.DEBUG)) { - _log.debug("Process: " + procArgs.toString()); - _log.debug("Name: " + this.getName() + ", DisplayName: " + this.getDisplayName()); + _log.debug("ShellService: Process: " + procArgs.toString()); + _log.debug("ShellService: Name: " + this.getName() + ", DisplayName: " + this.getDisplayName()); } _commandPath = procArgs.get(0); @@ -88,38 +88,51 @@ public class ShellService implements ClientApp { File exe = new File(_commandPath); if (!exe.exists()) { if (_log.shouldLog(Log.ERROR)) - _log.error("Command does not exist: " + _commandPath); + _log.error("ShellService: Command does not exist: " + _commandPath); throw new RuntimeException("Command does not exist: " + _commandPath); } if (!exe.canExecute()) { if (_log.shouldLog(Log.WARN)) - _log.warn("Command is not executable: " + _commandPath + " marking it executable"); + _log.warn("ShellService: Command is not executable: " + _commandPath + " marking it executable"); exe.setExecutable(true); } _pb = new ProcessBuilder(procArgs); if (_log.shouldDebug()) - _log.debug("ProcessBuilder: " + _pb.command().toString() + " is built"); + _log.debug("ShellService: ProcessBuilder: " + _pb.command().toString() + " is built"); - File pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + this.getName()); + String tmp_name = this.getName(); + File pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + tmp_name); if (!pluginDir.exists()) - pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + this.getName()+"-"+SystemVersion.getOS()+"-"+SystemVersion.getArch()); - if (!pluginDir.exists()) - pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + this.getName()+"-"+SystemVersion.getOS()); - if (!pluginDir.exists()) - throw new RuntimeException("Plugin directory does not exist: " + pluginDir.getAbsolutePath()); + pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + tmp_name+"-"+SystemVersion.getOS()+"-"+SystemVersion.getArch()); + + if (!pluginDir.exists()) { + pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + tmp_name+"-"+SystemVersion.getOS()); + if (!pluginDir.exists()) + throw new RuntimeException("Plugin directory does not exist: " + pluginDir.getAbsolutePath()); + else{ + this.name = tmp_name+"-"+SystemVersion.getOS(); + if (_log.shouldDebug()) + _log.debug("ShellService: Plugin name revised to match directory: " + this.getName()); + } + } else { + this.name = tmp_name+"-"+SystemVersion.getOS()+"-"+SystemVersion.getArch(); + if (_log.shouldDebug()) + _log.debug("ShellService: Plugin name revised to match directory: " + this.getName()); + } + _errorLog = new File(pluginDir, "error.log"); _outputLog = new File(pluginDir, "output.log"); _pb.redirectOutput(_outputLog); _pb.redirectError(_errorLog); if (_log.shouldLog(Log.DEBUG)) - _log.debug("Logs: " + _errorLog.getAbsolutePath() + ", " + _outputLog.getAbsolutePath()); + _log.debug("ShellService: Logs: " + _errorLog.getAbsolutePath() + ", " + _outputLog.getAbsolutePath()); _pb.directory(pluginDir); if (_log.shouldDebug()) - _log.debug("ProcessBuilder: " + _pb.directory() + " is set"); + _log.debug("ShellService: ProcessBuilder: " + _pb.directory() + " is set"); changeState(ClientAppState.INITIALIZED, "ShellService: " + getName() + " setup and initialized"); } @@ -175,17 +188,17 @@ public class ShellService implements ClientApp { File exe = new File(_commandPath); if (!exe.exists()) { if (_log.shouldLog(Log.ERROR)) - _log.error("Command does not exist: " + _commandPath); + _log.error("ShellService: Command does not exist: " + _commandPath); throw new RuntimeException("Command does not exist: " + _commandPath); } if (!exe.canExecute()) { if (_log.shouldLog(Log.WARN)) - _log.warn("Command is not executable: " + _commandPath + " marking it executable"); + _log.warn("ShellService: Command is not executable: " + _commandPath + " marking it executable"); exe.setExecutable(true); } if (getName().equals("unnamedClient")) { if (_log.shouldLog(Log.WARN)) - _log.warn("ShellService has no name, not starting"); + _log.warn("ShellService: ShellService has no name, not starting"); return; } changeState(ClientAppState.STARTING, "ShellService: " + getName() + " starting"); @@ -193,9 +206,9 @@ public class ShellService implements ClientApp { if (start) { _p = _pb.start(); if (!_p.isAlive() && _log.shouldLog(Log.ERROR)) - _log.error("Error getting Process of application from recently instantiated shellservice " + _pb.command()+" "+_p.exitValue()); + _log.error("ShellService: Error getting Process of application from recently instantiated shellservice " + _pb.command()+" "+_p.exitValue()); if (_log.shouldLog(Log.DEBUG)) - _log.debug("Started " + getName() + "process"); + _log.debug("ShellService: Started " + getName() + "process"); } if (_p.isAlive()) changeState(ClientAppState.RUNNING, "ShellService: " + getName() + " started"); @@ -234,7 +247,7 @@ public class ShellService implements ClientApp { if (_p == null) return false; if (_log.shouldLog(Log.DEBUG)) - _log.debug("Checking process status " + getName() + _p.isAlive()); + _log.debug("ShellService: Checking process status " + getName() + _p.isAlive()); return _p.isAlive(); } @@ -246,13 +259,13 @@ public class ShellService implements ClientApp { public synchronized void shutdown(String[] args) throws Throwable { if (getName().equals("unnamedClient")) { if (_log.shouldLog(Log.WARN)) - _log.warn("ShellService has no name, not shutting down"); + _log.warn("ShellService: ShellService has no name, not shutting down"); return; } changeState(ClientAppState.STOPPING, "ShellService: " + getName() + " stopping"); if (_p != null) { if (_log.shouldLog(Log.DEBUG)) - _log.debug("Stopping " + getName() + "process started with ShellService " + getName()); + _log.debug("ShellService: Stopping " + getName() + "process started with ShellService " + getName()); _p.destroy(); } changeState(ClientAppState.STOPPED, "ShellService: " + getName() + " stopped"); @@ -269,7 +282,7 @@ public class ShellService implements ClientApp { public ClientAppState getState() { if (!isProcessRunning()) { if (_log.shouldLog(Log.DEBUG)) - _log.debug("Process is not running " + getName()); + _log.debug("ShellService: Process is not running " + getName()); changeState(ClientAppState.STOPPED, "ShellService: " + getName() + " stopped"); _cmgr.unregister(this); }