Check for occupied beacon

This commit is contained in:
crschnick 2024-07-11 05:39:05 +00:00
parent ac07f21fd4
commit 6541a84972
2 changed files with 17 additions and 0 deletions

View file

@ -132,6 +132,14 @@ public class LauncherCommand implements Callable<Integer> {
+ " is already locked. Is another instance running?");
OperationMode.halt(1);
}
// If an instance is running as another user, we cannot connect to it as the xpipe_auth file is inaccessible
// Therefore the beacon client is not present.
// We still should check whether it is somehow occupied, otherwise beacon server startup will fail
if (BeaconClient.isOccupied(port)) {
TrackEvent.info("Another instance is already running on this port as another user. Quitting ...");
OperationMode.halt(1);
}
}
private XPipeDaemonMode getEffectiveMode() {

View file

@ -24,6 +24,15 @@ public class BeaconClient {
this.port = port;
}
public static boolean isOccupied(int port) {
var file = XPipeInstallation.getLocalBeaconAuthFile();
var reachable = BeaconServer.isReachable(port);
if (!Files.exists(file) && !reachable) {
return false;
}
return reachable;
}
public static BeaconClient establishConnection(int port, BeaconClientInformation information) throws Exception {
var client = new BeaconClient(port);
var auth = Files.readString(XPipeInstallation.getLocalBeaconAuthFile());