Fix beacon server start up on Linux again

This commit is contained in:
Christopher Schnick 2022-12-16 16:45:39 +01:00
parent afd5dd4553
commit a2cdcb149a
2 changed files with 25 additions and 11 deletions

View file

@ -10,7 +10,6 @@ import lombok.experimental.UtilityClass;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.file.Path;
/**
* Contains basic functionality to start, communicate, and stop a remote beacon server.
@ -43,10 +42,12 @@ public class BeaconServer {
}
public static Process start(String installationBase) throws Exception {
var daemonExecutable = getDaemonExecutable(installationBase);
var daemonExecutable = getDaemonDebugExecutable(installationBase);
// Tell daemon that we launched from an external tool
var command = "\"" + daemonExecutable + "\" --external "
+ (BeaconConfig.getDaemonArguments() != null ? BeaconConfig.getDaemonArguments() : "");
var command = BeaconConfig.launchDaemonInDebugMode()
? XPipeInstallation.createExternalAsyncLaunchCommand(
installationBase, BeaconConfig.getDaemonArguments())
: XPipeInstallation.createExternalLaunchCommand(getDaemonDebugExecutable(installationBase), BeaconConfig.getDaemonArguments());
Process process =
Runtime.getRuntime().exec(ShellTypes.getPlatformDefault().executeCommandWithShell(command));
printDaemonOutput(process, command);
@ -106,19 +107,18 @@ public class BeaconServer {
return res.isSuccess();
}
public static Path getDaemonExecutable(String installationBase) throws Exception {
public static String getDaemonDebugExecutable(String installationBase) throws Exception {
try (ShellProcessControl pc = new LocalStore().create().start()) {
var debug = BeaconConfig.launchDaemonInDebugMode();
if (!debug) {
return Path.of(
FileNames.join(installationBase, XPipeInstallation.getDaemonExecutablePath(pc.getOsType())));
throw new IllegalStateException();
} else {
if (BeaconConfig.attachDebuggerToDaemon()) {
return Path.of(FileNames.join(
installationBase, XPipeInstallation.getDaemonDebugAttachScriptPath(pc.getOsType())));
return FileNames.join(
installationBase, XPipeInstallation.getDaemonDebugAttachScriptPath(pc.getOsType()));
} else {
return Path.of(FileNames.join(
installationBase, XPipeInstallation.getDaemonDebugScriptPath(pc.getOsType())));
return FileNames.join(
installationBase, XPipeInstallation.getDaemonDebugScriptPath(pc.getOsType()));
}
}
}

View file

@ -11,6 +11,20 @@ import java.util.List;
public class XPipeInstallation {
public static String createExternalAsyncLaunchCommand(String installationBase, String arguments) {
var suffix = (arguments != null ? arguments : "");
if (OsType.getLocal().equals(OsType.LINUX)) {
return "nohup \"" + installationBase + "/app/bin/xpiped\" --external & disown" + suffix;
}
return FileNames.join(installationBase, XPipeInstallation.getDaemonExecutablePath(OsType.getLocal())) + suffix;
}
public static String createExternalLaunchCommand(String command, String arguments) {
var suffix = (arguments != null ? arguments : "");
return "\"" + command + "\" --external" + suffix;
}
public static String getInstallationBasePathForCLI(ShellProcessControl p, String cliExecutable) throws Exception {
var defaultInstallation = getDefaultInstallationBasePath(p, true);
if (cliExecutable == null) {