diff --git a/control-connector/src/main/java/org/polypheny/control/client/PolyphenyControlConnector.java b/control-connector/src/main/java/org/polypheny/control/client/PolyphenyControlConnector.java index 2de9e2c..bd388a7 100644 --- a/control-connector/src/main/java/org/polypheny/control/client/PolyphenyControlConnector.java +++ b/control-connector/src/main/java/org/polypheny/control/client/PolyphenyControlConnector.java @@ -174,6 +174,11 @@ String getStatus() { } + boolean checkForAnyRunningPolyphenyInstances() { + return Boolean.parseBoolean( executeGet( "/control/checkAnyRunningPolyphenyInstances" ) ); + } + + private String executeGet( String command ) { HttpResponse httpResponse; try { diff --git a/src/main/java/org/polypheny/control/control/Control.java b/src/main/java/org/polypheny/control/control/Control.java index b228489..4ca48c8 100644 --- a/src/main/java/org/polypheny/control/control/Control.java +++ b/src/main/java/org/polypheny/control/control/Control.java @@ -158,6 +158,11 @@ public void getStatus( Context ctx ) { } + public void checkAnyRunningPolyphenyInstances( Context ctx ) { + ctx.result( ServiceManager.getPidOfRunningPolyphenyInstances().size() + "" ); + } + + public void getVersion( Context ctx ) { ctx.result( gson.toJson( ServiceManager.getVersion() ) ); } diff --git a/src/main/java/org/polypheny/control/control/PolyphenyDbProcess.java b/src/main/java/org/polypheny/control/control/PolyphenyDbProcess.java index 5fd53bd..ee41c51 100644 --- a/src/main/java/org/polypheny/control/control/PolyphenyDbProcess.java +++ b/src/main/java/org/polypheny/control/control/PolyphenyDbProcess.java @@ -263,7 +263,6 @@ public void killForcibly() { } catch ( InterruptedException e ) { log.warn( "Interrupted while waiting for kill to finish." ); } - } else { super.process.destroyForcibly(); } diff --git a/src/main/java/org/polypheny/control/control/ServiceManager.java b/src/main/java/org/polypheny/control/control/ServiceManager.java index 788232a..021299f 100644 --- a/src/main/java/org/polypheny/control/control/ServiceManager.java +++ b/src/main/java/org/polypheny/control/control/ServiceManager.java @@ -179,10 +179,10 @@ public static boolean start( final ClientCommunicationStream clientCommunication // LinkedList javaOptionsFull = new LinkedList<>( javaOptions ); - String applicationConfFileName = new File( new File( workingDir ), "config" ).getAbsolutePath() + File.separator + "application.conf"; + /*String applicationConfFileName = new File( new File( workingDir ), "config" ).getAbsolutePath() + File.separator + "application.conf"; if ( new File( applicationConfFileName ).exists() ) { javaOptionsFull.addFirst( "-Dconfig.file=" + applicationConfFileName ); - } + }*/ javaOptionsFull.addFirst( "-Xmx" + javaMaximumHeapSize + "G" ); // Build list of arguments @@ -992,6 +992,32 @@ public static Object getStatus() { } + public static List getPidOfRunningPolyphenyInstances() { + if ( SystemUtils.IS_OS_WINDOWS ) { + throw new RuntimeException( "This operation is not supported on Windows" ); + } + try { + List pids = new ArrayList<>(); + Process process = Runtime.getRuntime().exec( "ps aux|grep org.polypheny.db.PolyphenyDb|grep -v grep|awk '{print $2}'" ); + try ( BufferedReader input = new BufferedReader( new InputStreamReader( process.getInputStream() ) ) ) { + String line; + while ( (line = input.readLine()) != null ) { + int id = Integer.parseInt( line ); + if ( polyphenyDbProcess != null && id != polyphenyDbProcess.getPid() ) { + log.warn( "There is a running Polypheny instance, but it has a unknown PID: {}", id ); + } + pids.add( id ); + } + } catch ( IOException e ) { + throw new RuntimeException( "IOException while checking if there are other instances of Polypheny.", e ); + } + return pids; + } catch ( IOException e ) { + throw new RuntimeException( "IOException while checking if there are other instances of Polypheny.", e ); + } + } + + private static boolean existsLocalBranchWithName( Git git, String branchName ) throws GitAPIException { List branches = git.branchList().call(); for ( Ref ref : branches ) { diff --git a/src/main/java/org/polypheny/control/httpinterface/Server.java b/src/main/java/org/polypheny/control/httpinterface/Server.java index ed55310..ec79e51 100644 --- a/src/main/java/org/polypheny/control/httpinterface/Server.java +++ b/src/main/java/org/polypheny/control/httpinterface/Server.java @@ -146,6 +146,7 @@ public Server( Control control, int port ) { javalin.get( "/control/pdbBranches", control::getAvailablePdbBranches ); javalin.get( "/control/puiBranches", control::getAvailablePuiBranches ); javalin.post( "/control/purgePolyphenyFolder", control::purgePolyphenyFolder ); + javalin.get( "/control/checkAnyRunningPolyphenyInstances", control::checkAnyRunningPolyphenyInstances ); // /polyfier javalin.post( "/polyfier/start", control::polyfierStart );