I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Verified Commit b2fe36b0 authored by idk's avatar idk
Browse files

Revise ShellService.name to match ShellService directory if the directory...

Revise ShellService.name to match ShellService directory if the directory includes -SystemVersion.getOS or -SystemVersion.getArch
parent 632a1578
No related branches found
No related tags found
No related merge requests found
...@@ -79,8 +79,8 @@ public class ShellService implements ClientApp { ...@@ -79,8 +79,8 @@ public class ShellService implements ClientApp {
ArrayList<String> procArgs = trimArgs(args); ArrayList<String> procArgs = trimArgs(args);
if (_log.shouldLog(Log.DEBUG)) { if (_log.shouldLog(Log.DEBUG)) {
_log.debug("Process: " + procArgs.toString()); _log.debug("ShellService: Process: " + procArgs.toString());
_log.debug("Name: " + this.getName() + ", DisplayName: " + this.getDisplayName()); _log.debug("ShellService: Name: " + this.getName() + ", DisplayName: " + this.getDisplayName());
} }
_commandPath = procArgs.get(0); _commandPath = procArgs.get(0);
...@@ -88,38 +88,51 @@ public class ShellService implements ClientApp { ...@@ -88,38 +88,51 @@ public class ShellService implements ClientApp {
File exe = new File(_commandPath); File exe = new File(_commandPath);
if (!exe.exists()) { if (!exe.exists()) {
if (_log.shouldLog(Log.ERROR)) 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); throw new RuntimeException("Command does not exist: " + _commandPath);
} }
if (!exe.canExecute()) { if (!exe.canExecute()) {
if (_log.shouldLog(Log.WARN)) 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); exe.setExecutable(true);
} }
_pb = new ProcessBuilder(procArgs); _pb = new ProcessBuilder(procArgs);
if (_log.shouldDebug()) 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()) if (!pluginDir.exists())
pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + this.getName()+"-"+SystemVersion.getOS()+"-"+SystemVersion.getArch()); pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + tmp_name+"-"+SystemVersion.getOS()+"-"+SystemVersion.getArch());
if (!pluginDir.exists())
pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + this.getName()+"-"+SystemVersion.getOS()); if (!pluginDir.exists()) {
if (!pluginDir.exists()) pluginDir = new File(_context.getConfigDir(), PLUGIN_DIR + '/' + tmp_name+"-"+SystemVersion.getOS());
throw new RuntimeException("Plugin directory does not exist: " + pluginDir.getAbsolutePath()); 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"); _errorLog = new File(pluginDir, "error.log");
_outputLog = new File(pluginDir, "output.log"); _outputLog = new File(pluginDir, "output.log");
_pb.redirectOutput(_outputLog); _pb.redirectOutput(_outputLog);
_pb.redirectError(_errorLog); _pb.redirectError(_errorLog);
if (_log.shouldLog(Log.DEBUG)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Logs: " + _errorLog.getAbsolutePath() + ", " + _outputLog.getAbsolutePath()); _log.debug("ShellService: Logs: " + _errorLog.getAbsolutePath() + ", " + _outputLog.getAbsolutePath());
_pb.directory(pluginDir); _pb.directory(pluginDir);
if (_log.shouldDebug()) 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"); changeState(ClientAppState.INITIALIZED, "ShellService: " + getName() + " setup and initialized");
} }
...@@ -175,17 +188,17 @@ public class ShellService implements ClientApp { ...@@ -175,17 +188,17 @@ public class ShellService implements ClientApp {
File exe = new File(_commandPath); File exe = new File(_commandPath);
if (!exe.exists()) { if (!exe.exists()) {
if (_log.shouldLog(Log.ERROR)) 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); throw new RuntimeException("Command does not exist: " + _commandPath);
} }
if (!exe.canExecute()) { if (!exe.canExecute()) {
if (_log.shouldLog(Log.WARN)) 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); exe.setExecutable(true);
} }
if (getName().equals("unnamedClient")) { if (getName().equals("unnamedClient")) {
if (_log.shouldLog(Log.WARN)) if (_log.shouldLog(Log.WARN))
_log.warn("ShellService has no name, not starting"); _log.warn("ShellService: ShellService has no name, not starting");
return; return;
} }
changeState(ClientAppState.STARTING, "ShellService: " + getName() + " starting"); changeState(ClientAppState.STARTING, "ShellService: " + getName() + " starting");
...@@ -193,9 +206,9 @@ public class ShellService implements ClientApp { ...@@ -193,9 +206,9 @@ public class ShellService implements ClientApp {
if (start) { if (start) {
_p = _pb.start(); _p = _pb.start();
if (!_p.isAlive() && _log.shouldLog(Log.ERROR)) 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)) if (_log.shouldLog(Log.DEBUG))
_log.debug("Started " + getName() + "process"); _log.debug("ShellService: Started " + getName() + "process");
} }
if (_p.isAlive()) if (_p.isAlive())
changeState(ClientAppState.RUNNING, "ShellService: " + getName() + " started"); changeState(ClientAppState.RUNNING, "ShellService: " + getName() + " started");
...@@ -234,7 +247,7 @@ public class ShellService implements ClientApp { ...@@ -234,7 +247,7 @@ public class ShellService implements ClientApp {
if (_p == null) if (_p == null)
return false; return false;
if (_log.shouldLog(Log.DEBUG)) 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(); return _p.isAlive();
} }
...@@ -246,13 +259,13 @@ public class ShellService implements ClientApp { ...@@ -246,13 +259,13 @@ public class ShellService implements ClientApp {
public synchronized void shutdown(String[] args) throws Throwable { public synchronized void shutdown(String[] args) throws Throwable {
if (getName().equals("unnamedClient")) { if (getName().equals("unnamedClient")) {
if (_log.shouldLog(Log.WARN)) 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; return;
} }
changeState(ClientAppState.STOPPING, "ShellService: " + getName() + " stopping"); changeState(ClientAppState.STOPPING, "ShellService: " + getName() + " stopping");
if (_p != null) { if (_p != null) {
if (_log.shouldLog(Log.DEBUG)) 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(); _p.destroy();
} }
changeState(ClientAppState.STOPPED, "ShellService: " + getName() + " stopped"); changeState(ClientAppState.STOPPED, "ShellService: " + getName() + " stopped");
...@@ -269,7 +282,7 @@ public class ShellService implements ClientApp { ...@@ -269,7 +282,7 @@ public class ShellService implements ClientApp {
public ClientAppState getState() { public ClientAppState getState() {
if (!isProcessRunning()) { if (!isProcessRunning()) {
if (_log.shouldLog(Log.DEBUG)) 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"); changeState(ClientAppState.STOPPED, "ShellService: " + getName() + " stopped");
_cmgr.unregister(this); _cmgr.unregister(this);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment