airavata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From samin...@apache.org
Subject git commit: https://issues.apache.org/jira/browse/AIRAVATA-1047
Date Mon, 10 Mar 2014 04:40:19 GMT
Repository: airavata
Updated Branches:
  refs/heads/master 0b6e1e5af -> 74a5d2a56


https://issues.apache.org/jira/browse/AIRAVATA-1047


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

Branch: refs/heads/master
Commit: 74a5d2a56369f384b0433f0678e822764fbbec27
Parents: 0b6e1e5
Author: Saminda Wijeratne <samindaw@gmail.com>
Authored: Mon Mar 10 00:40:01 2014 -0400
Committer: Saminda Wijeratne <samindaw@gmail.com>
Committed: Mon Mar 10 00:40:01 2014 -0400

----------------------------------------------------------------------
 .../src/main/resources/bin/airavata-server.sh   | 46 ++++++++++------
 .../org/apache/airavata/server/ServerMain.java  | 56 ++++++++++++++++----
 2 files changed, 77 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/airavata/blob/74a5d2a5/modules/distribution/airavata-server/src/main/resources/bin/airavata-server.sh
----------------------------------------------------------------------
diff --git a/modules/distribution/airavata-server/src/main/resources/bin/airavata-server.sh
b/modules/distribution/airavata-server/src/main/resources/bin/airavata-server.sh
index 4d40f0b..37026ee 100755
--- a/modules/distribution/airavata-server/src/main/resources/bin/airavata-server.sh
+++ b/modules/distribution/airavata-server/src/main/resources/bin/airavata-server.sh
@@ -26,8 +26,11 @@ then
 fi
 
 JAVA_OPTS=""
-while [ $# -ge 1 ]; do
-    case $1 in
+AIRAVATA_COMMAND=""
+IS_DAEMON_MODE=false
+for var in "$@"
+do
+    case $var in
         -xdebug)
             JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8000"
             shift
@@ -36,25 +39,38 @@ while [ $# -ge 1 ]; do
             JAVA_OPTS="$JAVA_OPTS -Djava.security.manager -Djava.security.policy=$AIRAVATA_HOME/conf/axis2.policy
-Daxis2.home=$AIRAVATA_HOME"
             shift
         ;;
+	start)
+	    IS_DAEMON_MODE=true
+            shift
+        ;;
         -h)
-            echo "Usage: airavata-server.sh"
-            echo "commands:"
-            echo "  -xdebug    Start Airavata Server under JPDA debugger"
-            echo "  -security  Enable Java 2 security"
-            echo "  -h         help"
+            echo "Usage: airavata-server.sh [command-options]"
+            echo "command options:"
+	    echo "  start                   Start server in daemon mode"
+	    echo "  stop [--serverIndex n]  Stop all airavata servers. Specify serverIndex stop
a particular instance"
+	    echo "  --<key>=<value>         Server setting(s) to override or introduce
(overrides values in airavata-server.properties)"
+            echo "  -xdebug                 Start Airavata Server under JPDA debugger"
+            echo "  -security               Enable Java 2 security"
+            echo "  -h                      Display this help and exit"
             shift
             exit 0
         ;;
-        *)
-            echo "Error: unknown command:$1"
-            echo "For help: airavata-server.sh -h"
+	*)
+	    AIRAVATA_COMMAND="$AIRAVATA_COMMAND $var"
             shift
-            exit 1
     esac
 done
 
-java $JAVA_OPTS -classpath "$XBAYA_CLASSPATH" \
-    -Djava.endorsed.dirs="$AIRAVATA_HOME/lib/endorsed":"$JAVA_HOME/jre/lib/endorsed":"$JAVA_HOME/lib/endorsed"
\
-    org.apache.airavata.server.ServerMain \
-    -repo "$AIRAVATA_HOME"/repository/services -conf "$AIRAVATA_HOME"/conf/axis2.xml $*
+if $IS_DAEMON_MODE ; then
+	echo ,"Starting airavata server in daemon mode..."
+	nohup java $JAVA_OPTS -classpath "$XBAYA_CLASSPATH" \
+	    -Djava.endorsed.dirs="$AIRAVATA_HOME/lib/endorsed":"$JAVA_HOME/jre/lib/endorsed":"$JAVA_HOME/lib/endorsed"
\
+	    org.apache.airavata.server.ServerMain $AIRAVATA_COMMAND $* > airavata-server.out
& 
+	echo
+	echo
+else
+	java $JAVA_OPTS -classpath "$XBAYA_CLASSPATH" \
+	    -Djava.endorsed.dirs="$AIRAVATA_HOME/lib/endorsed":"$JAVA_HOME/jre/lib/endorsed":"$JAVA_HOME/lib/endorsed"
\
+	    org.apache.airavata.server.ServerMain $AIRAVATA_COMMAND $*
+fi
 

http://git-wip-us.apache.org/repos/asf/airavata/blob/74a5d2a5/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
----------------------------------------------------------------------
diff --git a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
index eb9efb2..5a51995 100644
--- a/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
+++ b/modules/server/src/main/java/org/apache/airavata/server/ServerMain.java
@@ -42,6 +42,7 @@ public class ServerMain {
     private final static Logger logger = LoggerFactory.getLogger(ServerMain.class);
     private static boolean serversLoaded=false;
 	private static final String stopFileNamePrefix = "airavata-server-stop";
+	private static int serverIndex=-1;
 	private static final String serverStartedFileNamePrefix = "airavata-server-start";
     static{
 		servers = new ArrayList<IServer>();
@@ -86,14 +87,27 @@ public class ServerMain {
 		CommandLine commandLineParser = StringUtil.getCommandLineParser(args);
 		
 		if (commandLineParser.getArgList().contains("stop")){
+			String serverIndexOption = "serverIndex";
+			if (commandLineParser.hasOption(serverIndexOption)){
+				serverIndex=Integer.parseInt(commandLineParser.getOptionValue(serverIndexOption));
+			}
 			if (isServerRunning()) {
-				logger.info("Requesting airavata server to stop...");
+				logger.info("Requesting airavata server"+(serverIndex==-1? "(s)":" instance "+serverIndex)+"
to stop...");
 				requestStop();
+				while(isServerRunning()){
+					try {
+						Thread.sleep(5000);
+					} catch (InterruptedException e) {
+						e.printStackTrace();
+					}
+				}
+				logger.info("Server"+(serverIndex==-1? "(s)":" instance "+serverIndex)+" stopped!!!");
 			}else{
-				logger.error("Server is not running!!!");
+				logger.error("Server"+(serverIndex==-1? "":" instance "+serverIndex)+" is not running!!!");
 			}
 		}else{
 			setServerStarted();
+			logger.info("Airavata server instance "+serverIndex+" starting...");
 			ServerSettings.mergeSettingsCommandLineArgs(args);
 			startAllServers();
 			while(!hasStopRequested()){
@@ -105,32 +119,50 @@ public class ServerMain {
 			}
 			if (hasStopRequested()){
 				stopAllServers();
-				stopRequestServed();
+				System.exit(0);
 			}
 		}
 	}
 
+	@SuppressWarnings("resource")
 	private static void requestStop() throws IOException {
 		//FIXME currently stop requests all the servers to stop
-		new File(stopFileNamePrefix).createNewFile();
+		File file = new File(getServerStopFileName());
+		file.createNewFile();
+		new RandomAccessFile(file, "rw").getChannel().lock();
+		file.deleteOnExit();
 	}
 	
 	private static boolean hasStopRequested(){
-		return new File(stopFileNamePrefix).exists();
+		return new File(getServerStopFileName()).exists() || new File(stopFileNamePrefix).exists();

 	}
-	
-	private static void stopRequestServed(){
-		new File(stopFileNamePrefix).delete();
+
+	private static String getServerStopFileName() {
+		return (serverIndex==-1)?stopFileNamePrefix:stopFileNamePrefix+serverIndex;
 	}
 
 	private static boolean isServerRunning(){
-		return new File(serverStartedFileNamePrefix).exists();
+		if (serverIndex==-1){
+			String[] files = new File(".").list();
+			for (String file : files) {
+				if (file.contains(serverStartedFileNamePrefix)){
+					return true;
+				}
+			}
+			return false;
+		}else{
+			return new File(getServerStartedFileName()).exists();
+		}
 	}
 	
 	@SuppressWarnings({ "resource" })
 	private static void setServerStarted(){
 		try {
-			File serverStartedFile = new File(serverStartedFileNamePrefix);
+			File serverStartedFile = null;
+			while(serverStartedFile==null || serverStartedFile.exists()){
+				serverIndex++;
+				serverStartedFile = new File(getServerStartedFileName());
+			}
 			serverStartedFile.createNewFile();
 			serverStartedFile.deleteOnExit();
 			new RandomAccessFile(serverStartedFile,"rw").getChannel().lock();
@@ -140,6 +172,10 @@ public class ServerMain {
 			e.printStackTrace();
 		}
 	}
+
+	private static String getServerStartedFileName() {
+		return serverStartedFileNamePrefix+serverIndex;
+	}
 	
 	
 	public static void stopAllServers() {


Mime
View raw message