mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-21 23:20:23 +00:00
Check for occupied beacon
This commit is contained in:
parent
ac07f21fd4
commit
6541a84972
2 changed files with 17 additions and 0 deletions
|
@ -132,6 +132,14 @@ public class LauncherCommand implements Callable<Integer> {
|
||||||
+ " is already locked. Is another instance running?");
|
+ " is already locked. Is another instance running?");
|
||||||
OperationMode.halt(1);
|
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() {
|
private XPipeDaemonMode getEffectiveMode() {
|
||||||
|
|
|
@ -24,6 +24,15 @@ public class BeaconClient {
|
||||||
this.port = port;
|
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 {
|
public static BeaconClient establishConnection(int port, BeaconClientInformation information) throws Exception {
|
||||||
var client = new BeaconClient(port);
|
var client = new BeaconClient(port);
|
||||||
var auth = Files.readString(XPipeInstallation.getLocalBeaconAuthFile());
|
var auth = Files.readString(XPipeInstallation.getLocalBeaconAuthFile());
|
||||||
|
|
Loading…
Reference in a new issue