From a2cdcb149a9aee3a1de3754b03c5c64446e06812 Mon Sep 17 00:00:00 2001 From: Christopher Schnick Date: Fri, 16 Dec 2022 16:45:39 +0100 Subject: [PATCH] Fix beacon server start up on Linux again --- .../java/io/xpipe/beacon/BeaconServer.java | 22 +++++++++---------- .../io/xpipe/core/util/XPipeInstallation.java | 14 ++++++++++++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java index c6bff90d..c386d2b4 100644 --- a/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java +++ b/beacon/src/main/java/io/xpipe/beacon/BeaconServer.java @@ -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())); } } } diff --git a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java index f3931450..6a33439c 100644 --- a/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java +++ b/core/src/main/java/io/xpipe/core/util/XPipeInstallation.java @@ -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) {