Repository: airavata
Updated Branches:
  refs/heads/develop 6efb535b0 -> eb62af942


fixing logging issue


Project: http://git-wip-us.apache.org/repos/asf/airavata/repo
Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/eb62af94
Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/eb62af94
Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/eb62af94

Branch: refs/heads/develop
Commit: eb62af94250c690c933b2f8d15fe620de23aa36f
Parents: 6efb535
Author: scnakandala <supun.nakand...@gmail.com>
Authored: Thu Oct 13 19:03:38 2016 -0400
Committer: scnakandala <supun.nakand...@gmail.com>
Committed: Thu Oct 13 19:03:38 2016 -0400

----------------------------------------------------------------------
 .../src/main/assembly/bin-assembly.xml          |  1 +
 .../src/main/resources/bin/sharing-registry.sh  |  8 +-
 .../sharing/registry/server/ServerMain.java     | 98 ++++++++++++++++++++
 .../registry/server/SharingRegistryServer.java  |  8 --
 4 files changed, 103 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/eb62af94/modules/sharing-registry/sharing-registry-distribution/src/main/assembly/bin-assembly.xml
----------------------------------------------------------------------
diff --git 
a/modules/sharing-registry/sharing-registry-distribution/src/main/assembly/bin-assembly.xml
 
b/modules/sharing-registry/sharing-registry-distribution/src/main/assembly/bin-assembly.xml
index b8fdfd4..cef9a11 100644
--- 
a/modules/sharing-registry/sharing-registry-distribution/src/main/assembly/bin-assembly.xml
+++ 
b/modules/sharing-registry/sharing-registry-distribution/src/main/assembly/bin-assembly.xml
@@ -43,6 +43,7 @@
             <outputDirectory>bin</outputDirectory>
             <includes>
                 <include>airavata-server.properties</include>
+                <include>log4j.properties</include>
             </includes>
         </fileSet>
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/eb62af94/modules/sharing-registry/sharing-registry-distribution/src/main/resources/bin/sharing-registry.sh
----------------------------------------------------------------------
diff --git 
a/modules/sharing-registry/sharing-registry-distribution/src/main/resources/bin/sharing-registry.sh
 
b/modules/sharing-registry/sharing-registry-distribution/src/main/resources/bin/sharing-registry.sh
index 44aef1f..02be943 100644
--- 
a/modules/sharing-registry/sharing-registry-distribution/src/main/resources/bin/sharing-registry.sh
+++ 
b/modules/sharing-registry/sharing-registry-distribution/src/main/resources/bin/sharing-registry.sh
@@ -62,10 +62,10 @@ done
 
 if $STOP;
 then
-       for f in `find . -name "*-start_*"`; do
+       for f in `find . -name "server_start_*"`; do
                IFS='_' read -a f_split <<< "$f"
                echo "Found process file : $f"
-               echo -n "    Sending kill signals to process ${f_split[1]}..."
+               echo -n "    Sending kill signals to process ${f_split[2]}..."
                out=`kill -9 ${f_split[1]} 2>&1`
                if [ -z "$out" ]; then
                    echo "done"
@@ -83,8 +83,8 @@ then
 else
        if $IS_DAEMON_MODE ; then
                echo "Starting Sharing Registry Server in daemon mode..."
-               nohup $JAVA_HOME/bin/java ${JAVA_OPTS} -classpath 
"$SHARING_REGISTRY_CLASSPATH"  
org.apache.airavata.sharing.registry.server.SharingRegistryServer > 
../sharing-registry.out & echo $! > "../sharing-registry-start_$!"
+               $JAVA_HOME/bin/java ${JAVA_OPTS} -classpath 
"$SHARING_REGISTRY_CLASSPATH"  
org.apache.airavata.sharing.registry.server.ServerMain $* > /dev/null 2>&1 &
        else
-               $JAVA_HOME/bin/java ${JAVA_OPTS} -classpath 
"$SHARING_REGISTRY_CLASSPATH"  
org.apache.airavata.sharing.registry.server.SharingRegistryServer
+               $JAVA_HOME/bin/java ${JAVA_OPTS} -classpath 
"$SHARING_REGISTRY_CLASSPATH"  
org.apache.airavata.sharing.registry.server.ServerMain $*
        fi
 fi
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/eb62af94/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/ServerMain.java
----------------------------------------------------------------------
diff --git 
a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/ServerMain.java
 
b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/ServerMain.java
new file mode 100644
index 0000000..54e1722
--- /dev/null
+++ 
b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/ServerMain.java
@@ -0,0 +1,98 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+package org.apache.airavata.sharing.registry.server;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+
+public class ServerMain {
+    private final static Logger logger = 
LoggerFactory.getLogger(ServerMain.class);
+
+    private static int serverPID = -1;
+    private static final String stopFileNamePrefix = "server_stop";
+    private static final String serverStartedFileNamePrefix = "server_start";
+
+    public static void main(String[] args) {
+        try {
+            setServerStarted();
+            new SharingRegistryServer().start();
+        } catch (Exception e) {
+            logger.error(e.getMessage(), e);
+        }
+    }
+
+    @SuppressWarnings({"resource"})
+    private static void setServerStarted() {
+        try {
+            serverPID = getPID();
+            deleteOldStopRequests();
+            File serverStartedFile = null;
+            serverStartedFile = new File(getServerStartedFileName());
+            serverStartedFile.createNewFile();
+            serverStartedFile.deleteOnExit();
+            new RandomAccessFile(serverStartedFile, "rw").getChannel().lock();
+        } catch (FileNotFoundException e) {
+            logger.error(e.getMessage(), e);
+        } catch (IOException e) {
+            logger.error(e.getMessage(), e);
+        }
+    }
+
+    private static String getServerStartedFileName() {
+        return new File(new File(System.getenv("" +
+                "SHARING_REGISTRY_HOME"), "bin"), serverStartedFileNamePrefix 
+ "_" + Integer.toString(serverPID)).toString();
+    }
+
+    private static int getPID() {
+        try {
+            java.lang.management.RuntimeMXBean runtime = 
java.lang.management.ManagementFactory
+                    .getRuntimeMXBean();
+            java.lang.reflect.Field jvm = runtime.getClass()
+                    .getDeclaredField("jvm");
+            jvm.setAccessible(true);
+            sun.management.VMManagement mgmt = (sun.management.VMManagement) 
jvm
+                    .get(runtime);
+            java.lang.reflect.Method pid_method = mgmt.getClass()
+                    .getDeclaredMethod("getProcessId");
+            pid_method.setAccessible(true);
+
+            int pid = (Integer) pid_method.invoke(mgmt);
+            return pid;
+        } catch (Exception e) {
+            return -1;
+        }
+    }
+
+    private static void deleteOldStopRequests() {
+        File[] files = new File(".").listFiles();
+        for (File file : files) {
+            if (file.getName().contains(stopFileNamePrefix)) {
+                file.delete();
+            }
+
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/airavata/blob/eb62af94/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServer.java
----------------------------------------------------------------------
diff --git 
a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServer.java
 
b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServer.java
index 23b215a..7b72227 100644
--- 
a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServer.java
+++ 
b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/server/SharingRegistryServer.java
@@ -108,14 +108,6 @@ public class SharingRegistryServer implements IServer {
         }
     }
 
-    public static void main(String[] args) {
-        try {
-            new SharingRegistryServer().start();
-        } catch (Exception e) {
-            logger.error(e.getMessage(), e);
-        }
-    }
-
     @Override
     public void stop() throws Exception {
         if (server!=null && server.isServing()){

Reply via email to