You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ya...@apache.org on 2025/06/30 05:34:44 UTC
(airavata) 06/07: simplify starter scripts
This is an automated email from the ASF dual-hosted git repository.
yasith pushed a commit to branch distribution-improvements
in repository https://gitbox.apache.org/repos/asf/airavata.git
commit a1de99acf9d26f51615ab1a5eb7d09ea2e487c44
Author: yasithdev <ya...@icloud.com>
AuthorDate: Sun Jun 29 19:15:47 2025 -0500
simplify starter scripts
---
.../src/main/resources/bin/load-client.sh | 84 ++++-----
.../load-client/src/main/resources/bin/setenv.sh | 142 ++++++++++++---
.../resources/distribution/bin/agent-service.sh | 167 +----------------
.../src/main/resources/distribution/bin/setenv.sh | 138 +++++++++++---
.../resources/distribution/bin/airavata-server.sh | 201 ++-------------------
.../main/resources/distribution/bin/controller.sh | 144 +--------------
.../resources/distribution/bin/email-monitor.sh | 144 +--------------
.../main/resources/distribution/bin/parser-wm.sh | 144 +--------------
.../main/resources/distribution/bin/participant.sh | 144 +--------------
.../src/main/resources/distribution/bin/post-wm.sh | 144 +--------------
.../src/main/resources/distribution/bin/pre-wm.sh | 144 +--------------
.../resources/distribution/bin/realtime-monitor.sh | 144 +--------------
.../src/main/resources/distribution/bin/setenv.sh | 140 +++++++++++---
.../resources/distribution/bin/sharing-registry.sh | 74 +-------
.../distribution/bin/start-network-server.sh | 180 ------------------
.../resources/distribution/bin/file-service.sh | 169 +----------------
.../src/main/resources/distribution/bin/setenv.sh | 138 +++++++++++---
.../resources/distribution/bin/research-service.sh | 167 +----------------
.../src/main/resources/distribution/bin/setenv.sh | 138 +++++++++++---
19 files changed, 665 insertions(+), 2081 deletions(-)
diff --git a/dev-tools/load-client/src/main/resources/bin/load-client.sh b/dev-tools/load-client/src/main/resources/bin/load-client.sh
index fe05e8d230..e10efac126 100644
--- a/dev-tools/load-client/src/main/resources/bin/load-client.sh
+++ b/dev-tools/load-client/src/main/resources/bin/load-client.sh
@@ -17,60 +17,40 @@
# specific language governing permissions and limitations
# under the License.
-. `dirname $0`/setenv.sh
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="logo.txt"
+# Source the common environment and functions
+. $(dirname $0)/setenv.sh
+# Client-specific configuration
+MAIN_CLASS="org.apache.airavata.tools.load.LoadClient"
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME}"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/airavata.out"
-LOG_FILE=$DEFAULT_LOG_FILE
-# parse command arguments
-for var in "$@"
-do
- case ${var} in
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "`echo "$LOG_FILE" | egrep "^/"`" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- -h)
- echo "Usage: load-client.sh"
-
- echo "command options:"
- echo " -config Load configuration file in yml format"
- echo " -apiHost API Server host name"
- echo " -apiPort API Server port"
- echo " -privateKeyPath SSH private key path to communicate with storage resources (Defaults to user private key in ~/.ssh/id_rsa)"
- echo " -publicKeyPath SSH public key path to communicate with storage resources (Defaults to user public key in ~/.ssh/id_rsa.pub)"
- echo " -passPhrase SSH private key pass phrase (if any)"
- echo " -h Display this help and exit"
- shift
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} ${var}"
- shift
- ;;
- esac
+# Parse client-specific arguments
+while (($# > 0)); do
+ case "$1" in
+ -xdebug)
+ JAVA_OPTS+=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8000"
+ shift
+ ;;
+ -h)
+ echo "Usage: load-client.sh"
+ echo ""
+ echo "command options:"
+ echo " -config Load configuration file in yml format"
+ echo " -apiHost API Server host name"
+ echo " -apiPort API Server port"
+ echo " -privateKeyPath SSH private key path to communicate with storage resources (Defaults to user private key in ~/.ssh/id_rsa)"
+ echo " -publicKeyPath SSH public key path to communicate with storage resources (Defaults to user public key in ~/.ssh/id_rsa.pub)"
+ echo " -passPhrase SSH private key pass phrase (if any)"
+ echo " -xdebug Start under JPDA debugger"
+ echo " -h Display this help and exit"
+ exit 0
+ ;;
+ *)
+ # Pass all other arguments to the Java application
+ break
+ ;;
+ esac
done
-echo $*
-java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" \
- org.apache.airavata.tools.load.LoadClient ${AIRAVATA_COMMAND} ${EXTRA_ARGS} $*
+# Run the load client
+java ${JAVA_OPTS} -classpath "${CLASSPATH}" ${MAIN_CLASS} "$@"
diff --git a/dev-tools/load-client/src/main/resources/bin/setenv.sh b/dev-tools/load-client/src/main/resources/bin/setenv.sh
index 9e894e1db7..59cc88d4d2 100644
--- a/dev-tools/load-client/src/main/resources/bin/setenv.sh
+++ b/dev-tools/load-client/src/main/resources/bin/setenv.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -7,9 +7,9 @@
# 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
@@ -17,30 +17,126 @@
# specific language governing permissions and limitations
# under the License.
-# resolve links - $0 may be a softlink
+# Resolve symlinks to get the real script location
PRG="$0"
-
-while [ -h "$PRG" ]; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '.*/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`/"$link"
- fi
+while [ -L "$PRG" ]; do
+ PRG=$(readlink "$PRG")
done
+PRGDIR=$(dirname "$PRG")
-PRGDIR=`dirname "$PRG"`
+# Set AIRAVATA_HOME if not already set
+[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=$(cd "$PRGDIR/.." && pwd)
-# Only set AIRAVATA_HOME if not already set
-[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=`cd "$PRGDIR/.." ; pwd`
+# Build CLASSPATH from all JAR files
+CLASSPATH=$(printf "%s:" "$AIRAVATA_HOME"/lib/*.jar)
+CLASSPATH=${CLASSPATH%:} # Remove trailing colon
-AIRAVATA_CLASSPATH=""
+export AIRAVATA_HOME CLASSPATH
-for f in "$AIRAVATA_HOME"/lib/*.jar
-do
- AIRAVATA_CLASSPATH="$AIRAVATA_CLASSPATH":$f
-done
+# Common function to run Airavata services
+# Usage: run_service <service_name> <main_class> <java_opts>
+run_service() {
+ local SERVICE_NAME="$1" MAIN_CLASS="$2" JAVA_OPTS="$3"
+ local CWD="$PWD" PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
+ local DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
+ local LOG_FILE="$DEFAULT_LOG_FILE" DAEMON_MODE=false EXTRA_ARGS=""
+
+ # Help text
+ local HELP_TEXT="Usage: ${SERVICE_NAME}.sh
+
+command options:
+ -d Run in daemon mode
+ -xdebug Start ${SERVICE_NAME} under JPDA debugger
+ -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)
+ -h Display this help and exit
+
+Daemon mode commands (use with -d):
+ start Start server in daemon mode
+ stop Stop server running in daemon mode
+ restart Restart server in daemon mode"
+
+ cd "${AIRAVATA_HOME}/bin"
+
+ # Helper function to stop daemon process
+ stop_daemon() {
+ if [[ -f "$PID_PATH_NAME" ]]; then
+ local PID=$(cat "$PID_PATH_NAME")
+ echo "$SERVICE_NAME stopping..."
+ kill "$PID"
+
+ local retry=0
+ while kill -0 "$PID" 2>/dev/null && ((retry++ < 20)); do
+ echo "[PID: $PID] Waiting for process to stop..."
+ sleep 1
+ done
+
+ if kill -0 "$PID" 2>/dev/null; then
+ echo "[PID: $PID] Forcefully killing non-responsive process..."
+ kill -9 "$PID"
+ fi
+
+ echo "$SERVICE_NAME is now stopped."
+ rm "$PID_PATH_NAME"
+ return 0
+ else
+ echo "$SERVICE_NAME is not running."
+ return 1
+ fi
+ }
+
+ # Helper function to start daemon process
+ start_daemon() {
+ echo "Starting $SERVICE_NAME ..."
+ if [[ ! -f "$PID_PATH_NAME" ]]; then
+ nohup java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" "$@" >"$LOG_FILE" 2>&1 &
+ echo $! >"$PID_PATH_NAME"
+ echo "$SERVICE_NAME now running: PID $(cat "$PID_PATH_NAME")"
+ else
+ echo "$SERVICE_NAME already running: PID $(cat "$PID_PATH_NAME")"
+ fi
+ }
+
+ # Parse command arguments
+ while (($# > 0)); do
+ case "$1" in
+ -d) DAEMON_MODE=true ;;
+ -xdebug) JAVA_OPTS+=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000" ;;
+ -log)
+ shift
+ LOG_FILE="$1"
+ [[ "$LOG_FILE" != /* ]] && LOG_FILE="${CWD}/${LOG_FILE}"
+ ;;
+ start | stop | restart)
+ if [[ "$DAEMON_MODE" == true ]]; then
+ case "$1" in
+ start) start_daemon "$@" ;;
+ stop) stop_daemon ;;
+ restart)
+ stop_daemon
+ start_daemon "$@"
+ ;;
+ esac
+ exit 0
+ else
+ EXTRA_ARGS+=" $1"
+ fi
+ ;;
+ -h)
+ echo "$HELP_TEXT"
+ exit 0
+ ;;
+ *) EXTRA_ARGS+=" $1" ;;
+ esac
+ shift
+ done
+
+ # Validate daemon mode usage
+ if [[ "$DAEMON_MODE" == true ]]; then
+ echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
+ echo "Use -h for help"
+ exit 1
+ fi
-export AIRAVATA_HOME
-export AIRAVATA_CLASSPATH
+ # Run in foreground mode
+ java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" $EXTRA_ARGS
+}
diff --git a/modules/agent-framework/agent-service/src/main/resources/distribution/bin/agent-service.sh b/modules/agent-framework/agent-service/src/main/resources/distribution/bin/agent-service.sh
index d3289c694c..f89493c3c2 100755
--- a/modules/agent-framework/agent-service/src/main/resources/distribution/bin/agent-service.sh
+++ b/modules/agent-framework/agent-service/src/main/resources/distribution/bin/agent-service.sh
@@ -18,170 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="agent-service"
MAIN_CLASS="org.apache.airavata.agent.connection.service.AgentServiceApplication"
+JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml -Dairavata.server.truststore.path=${AIRAVATA_HOME}/conf/airavata.jks -Dspring.config.location=${AIRAVATA_HOME}/conf/"
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
-JAVA_OPTS="-Dairavata.server.truststore.path=${AIRAVATA_HOME}/conf/airavata.jks -Dspring.config.location=${AIRAVATA_HOME}/conf/ -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# Function to start the service
-start_service() {
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME in daemon mode..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is already running ..."
- fi
- else
- echo "Starting $SERVICE_NAME in interactive mode..."
- java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $*
- fi
-}
-
-# Function to stop the service
-stop_service() {
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
-}
-
-# Function to restart the service
-restart_service() {
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- fi
- start_service $*
-}
-
-# Function to show help
-show_help() {
- echo "Usage: agent-service.sh [options] [command]"
- echo ""
- echo "Commands (daemon mode only):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- echo ""
- echo "Options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Connection Service under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Examples:"
- echo " agent-service.sh # Run in interactive mode"
- echo " agent-service.sh -d start # Start in daemon mode"
- echo " agent-service.sh -d stop # Stop daemon"
- echo " agent-service.sh -d restart # Restart daemon"
- echo " agent-service.sh -xdebug # Run with debugger in interactive mode"
-}
-
-# parse command arguments
-for var in "$@"; do
- case ${var} in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- start_service $*
- exit 0
- else
- echo "Error: 'start' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- stop_service
- exit 0
- else
- echo "Error: 'stop' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- restart_service $*
- exit 0
- else
- echo "Error: 'restart' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- -h)
- show_help
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} ${var}"
- shift
- ;;
- esac
-done
-
-# If no specific command was given, run in interactive mode
-if [ "$DAEMON_MODE" = false ]; then
- java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $*
-fi
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/agent-framework/agent-service/src/main/resources/distribution/bin/setenv.sh b/modules/agent-framework/agent-service/src/main/resources/distribution/bin/setenv.sh
index 3f1d7632bf..59cc88d4d2 100755
--- a/modules/agent-framework/agent-service/src/main/resources/distribution/bin/setenv.sh
+++ b/modules/agent-framework/agent-service/src/main/resources/distribution/bin/setenv.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,30 +17,126 @@
# specific language governing permissions and limitations
# under the License.
-# resolve links - $0 may be a softlink
+# Resolve symlinks to get the real script location
PRG="$0"
-
-while [ -h "$PRG" ]; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '.*/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`/"$link"
- fi
+while [ -L "$PRG" ]; do
+ PRG=$(readlink "$PRG")
done
+PRGDIR=$(dirname "$PRG")
-PRGDIR=`dirname "$PRG"`
+# Set AIRAVATA_HOME if not already set
+[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=$(cd "$PRGDIR/.." && pwd)
-# Only set AIRAVATA_HOME if not already set
-[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=`cd "$PRGDIR/.." ; pwd`
+# Build CLASSPATH from all JAR files
+CLASSPATH=$(printf "%s:" "$AIRAVATA_HOME"/lib/*.jar)
+CLASSPATH=${CLASSPATH%:} # Remove trailing colon
-AIRAVATA_CLASSPATH=""
+export AIRAVATA_HOME CLASSPATH
-for f in "$AIRAVATA_HOME"/lib/*.jar
-do
- AIRAVATA_CLASSPATH="$AIRAVATA_CLASSPATH":$f
-done
+# Common function to run Airavata services
+# Usage: run_service <service_name> <main_class> <java_opts>
+run_service() {
+ local SERVICE_NAME="$1" MAIN_CLASS="$2" JAVA_OPTS="$3"
+ local CWD="$PWD" PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
+ local DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
+ local LOG_FILE="$DEFAULT_LOG_FILE" DAEMON_MODE=false EXTRA_ARGS=""
+
+ # Help text
+ local HELP_TEXT="Usage: ${SERVICE_NAME}.sh
+
+command options:
+ -d Run in daemon mode
+ -xdebug Start ${SERVICE_NAME} under JPDA debugger
+ -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)
+ -h Display this help and exit
+
+Daemon mode commands (use with -d):
+ start Start server in daemon mode
+ stop Stop server running in daemon mode
+ restart Restart server in daemon mode"
+
+ cd "${AIRAVATA_HOME}/bin"
+
+ # Helper function to stop daemon process
+ stop_daemon() {
+ if [[ -f "$PID_PATH_NAME" ]]; then
+ local PID=$(cat "$PID_PATH_NAME")
+ echo "$SERVICE_NAME stopping..."
+ kill "$PID"
+
+ local retry=0
+ while kill -0 "$PID" 2>/dev/null && ((retry++ < 20)); do
+ echo "[PID: $PID] Waiting for process to stop..."
+ sleep 1
+ done
+
+ if kill -0 "$PID" 2>/dev/null; then
+ echo "[PID: $PID] Forcefully killing non-responsive process..."
+ kill -9 "$PID"
+ fi
+
+ echo "$SERVICE_NAME is now stopped."
+ rm "$PID_PATH_NAME"
+ return 0
+ else
+ echo "$SERVICE_NAME is not running."
+ return 1
+ fi
+ }
+
+ # Helper function to start daemon process
+ start_daemon() {
+ echo "Starting $SERVICE_NAME ..."
+ if [[ ! -f "$PID_PATH_NAME" ]]; then
+ nohup java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" "$@" >"$LOG_FILE" 2>&1 &
+ echo $! >"$PID_PATH_NAME"
+ echo "$SERVICE_NAME now running: PID $(cat "$PID_PATH_NAME")"
+ else
+ echo "$SERVICE_NAME already running: PID $(cat "$PID_PATH_NAME")"
+ fi
+ }
+
+ # Parse command arguments
+ while (($# > 0)); do
+ case "$1" in
+ -d) DAEMON_MODE=true ;;
+ -xdebug) JAVA_OPTS+=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000" ;;
+ -log)
+ shift
+ LOG_FILE="$1"
+ [[ "$LOG_FILE" != /* ]] && LOG_FILE="${CWD}/${LOG_FILE}"
+ ;;
+ start | stop | restart)
+ if [[ "$DAEMON_MODE" == true ]]; then
+ case "$1" in
+ start) start_daemon "$@" ;;
+ stop) stop_daemon ;;
+ restart)
+ stop_daemon
+ start_daemon "$@"
+ ;;
+ esac
+ exit 0
+ else
+ EXTRA_ARGS+=" $1"
+ fi
+ ;;
+ -h)
+ echo "$HELP_TEXT"
+ exit 0
+ ;;
+ *) EXTRA_ARGS+=" $1" ;;
+ esac
+ shift
+ done
+
+ # Validate daemon mode usage
+ if [[ "$DAEMON_MODE" == true ]]; then
+ echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
+ echo "Use -h for help"
+ exit 1
+ fi
-export AIRAVATA_HOME
-export AIRAVATA_CLASSPATH
\ No newline at end of file
+ # Run in foreground mode
+ java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" $EXTRA_ARGS
+}
diff --git a/modules/distribution/src/main/resources/distribution/bin/airavata-server.sh b/modules/distribution/src/main/resources/distribution/bin/airavata-server.sh
index 05d15fdfdd..ed4cadb07b 100755
--- a/modules/distribution/src/main/resources/distribution/bin/airavata-server.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/airavata-server.sh
@@ -18,210 +18,45 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="airavata-server"
MAIN_CLASS="org.apache.airavata.server.ServerMain"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-IS_DAEMON_MODE=false
-LOGO=true
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-FORCE=false
-ACTION=""
-# parse command arguments
-while [ $# -gt 0 ]; do
+SERVERS=""
+ARGS=()
+while [[ $# -gt 0 ]]; do
case $1 in
- -d)
- IS_DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
-security)
- JAVA_OPTS="${JAVA_OPTS} -Djava.security.manager -Djava.security.policy=${AIRAVATA_HOME}/conf/axis2.policy -Daxis2.home=${AIRAVATA_HOME}"
+ JAVA_OPTS+=" -Djava.security.manager -Djava.security.policy=${AIRAVATA_HOME}/conf/axis2.policy -Daxis2.home=${AIRAVATA_HOME}"
shift
;;
-enableLegacyTLS)
- # Enable TLS v1 and v1.1. disableSystemPropertiesFile is needed
- # because the system properties file takes precedence. See 'man update-crypto-policies' for more info.
- JAVA_OPTS="${JAVA_OPTS} -Djava.security.policy=${AIRAVATA_HOME}/bin/enableLegacyTLS.security -Djava.security.disableSystemPropertiesFile=true"
- shift
- ;;
- -nologo)
- LOGO=false
- shift
- ;;
- -log)
- shift
- if [ $# -eq 0 ]; then
- echo "Error: -log requires a filename"
- exit 1
- fi
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- -f | --force)
- FORCE=true
+ JAVA_OPTS+=" -Djava.security.policy=${AIRAVATA_HOME}/bin/enableLegacyTLS.security -Djava.security.disableSystemPropertiesFile=true"
shift
;;
- start)
- ACTION="start"
+ apiserver | gfac | orchestrator | credentialstore | regserver)
+ if [ -z "$SERVERS" ]; then SERVERS="$1"; else SERVERS="$SERVERS,$1"; fi
shift
;;
- stop)
- ACTION="stop"
+ all | api-orch | execution)
+ SERVERS="$1"
shift
;;
- -h)
- echo "Usage: airavata-server [command-options] {start|stop}"
- echo ""
- echo "Commands:"
- echo " start Start Airavata server(s)"
- echo " stop Stop Airavata server(s)"
- echo ""
- echo "Server names (for start command):"
- echo " apiserver Start apiserver"
- echo " gfac Start gfac server"
- echo " orchestrator Start orchestrator server"
- echo " credentialstore Start credentialstore server"
- echo " regserver Start registry server"
- echo " all Start all servers in one JVM"
- echo " api-orch Start API and orchestrator servers"
- echo " execution Start execution-related servers"
- echo ""
- echo "Command options:"
- echo " -d Start server in daemon mode"
- echo " -xdebug Start Airavata Server under JPDA debugger"
- echo " -nologo Do not show airavata logo"
- echo " -security Enable Java 2 security"
- echo " -enableLegacyTLS Enable TLS v1 and v1.1"
- echo " -f, --force Force stop all servers (for stop command)"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " --<key>[=<value>] Server setting(s) to override or introduce (overrides values in airavata-server.properties)"
- echo " -h Display this help and exit"
- echo ""
- echo "Examples:"
- echo " airavata-server start apiserver"
- echo " airavata-server -d start api-orch"
- echo " airavata-server start -d -log custom.log all"
- echo " airavata-server -d stop"
- echo " airavata-server stop -f"
- exit 0
- ;;
*)
- # Handle server names and other arguments based on action
- if [ "$ACTION" = "start" ]; then
- case $1 in
- apiserver | gfac | orchestrator | credentialstore | regserver)
- if [ -z ${SERVERS} ]; then
- SERVERS="${1}"
- else
- SERVERS="${SERVERS},${1}"
- fi
- ;;
- all | api-orch | execution)
- IS_SUBSET=true
- SUBSET="${1}"
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- ;;
- esac
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- fi
+ ARGS+=("$1")
shift
;;
esac
done
-
-# Check if action was specified
-if [ -z "$ACTION" ]; then
- echo "Error: No action specified. Use 'start' or 'stop'"
- echo "Use -h for help"
- exit 1
-fi
-
-# Validate force flag usage
-if [ "$FORCE" = true ] && [ "$ACTION" != "stop" ]; then
- echo "Error: -f/--force flag is only valid with 'stop' command"
- exit 1
-fi
-
-# Handle start action
-if [ "$ACTION" = "start" ]; then
- # Construct Airavata command arguments in proper order.
- if ${IS_SUBSET}; then
- AIRAVATA_COMMAND="--servers=${SUBSET} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}"
+CONSTRUCTED_ARGS=()
+if [[ " ${ARGS[*]} " =~ " start " ]]; then
+ if [ -n "$SERVERS" ]; then
+ CONSTRUCTED_ARGS+=("--servers=${SERVERS}")
else
- if [ -z ${SERVERS} ]; then
- echo "You should provide at least one server component to start the airavata server. Please use -h option to get more details."
- exit 1
- else
- AIRAVATA_COMMAND="--servers=${SERVERS} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}"
- fi
- fi
-
- # Print logo file
- if ${LOGO}; then
- if [ -e ${LOGO_FILE} ]; then
- cat ${LOGO_FILE}
- fi
- fi
-
- if ${IS_DAEMON_MODE}; then
- echo "Starting ${SERVICE_NAME} in daemon mode..."
- echo "Redirecting output to $LOG_FILE"
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started with PID $(cat $PID_PATH_NAME)"
- else
- java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND}
+ echo "You should provide at least one server component to start the airavata server. Please use -h option to get more details."
+ exit 1
fi
fi
-# Handle stop action
-if [ "$ACTION" = "stop" ]; then
- if ${FORCE}; then
- for f in $(find . -name "server_start_*"); do
- # split file name using "_" underscore
- f_split=(${f//_/ })
- echo "Found process file : $f"
- echo -n " Sending kill signals to process ${f_split[2]}..."
- out=$(kill -9 ${f_split[2]} 2>&1)
- if [ -z "$out" ]; then
- echo "done"
- else
- echo "failed (REASON: $out)"
- fi
- echo -n " Removing process file..."
- out=$(rm ${f} 2>&1)
- if [ -z "$out" ]; then
- echo "done"
- else
- echo "failed (REASON: $out)"
- fi
- done
- else
- java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} stop ${AIRAVATA_COMMAND} ${EXTRA_ARGS}
- fi
-fi
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "${ARGS[@]}" "${CONSTRUCTED_ARGS[@]}"
diff --git a/modules/distribution/src/main/resources/distribution/bin/controller.sh b/modules/distribution/src/main/resources/distribution/bin/controller.sh
old mode 100644
new mode 100755
index a114d38525..4e145cd5ee
--- a/modules/distribution/src/main/resources/distribution/bin/controller.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/controller.sh
@@ -18,149 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="controller"
MAIN_CLASS="org.apache.airavata.helix.impl.controller.HelixController"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-LOGO=true
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# parse command arguments
-while [ $# -gt 0 ]; do
- case $1 in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME ..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started with PID $(cat $PID_PATH_NAME)"
- else
- echo "$SERVICE_NAME is already running with PID $(cat $PID_PATH_NAME)"
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- echo "$SERVICE_NAME starting ..."
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- -h)
- echo "Usage: controller.sh"
-
- echo "command options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Controller under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Daemon mode commands (use with -d):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- ;;
- esac
-done
-
-# If in daemon mode but no daemon command specified, show error
-if [ "$DAEMON_MODE" = true ]; then
- echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
- echo "Use -h for help"
- exit 1
-fi
-# Run in foreground mode
-java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/distribution/src/main/resources/distribution/bin/email-monitor.sh b/modules/distribution/src/main/resources/distribution/bin/email-monitor.sh
old mode 100644
new mode 100755
index 10243a9661..beb11ebbad
--- a/modules/distribution/src/main/resources/distribution/bin/email-monitor.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/email-monitor.sh
@@ -18,149 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="email-monitor"
MAIN_CLASS="org.apache.airavata.monitor.email.EmailBasedMonitor"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-LOGO=true
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# parse command arguments
-while [ $# -gt 0 ]; do
- case $1 in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME ..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started with PID $(cat $PID_PATH_NAME)"
- else
- echo "$SERVICE_NAME is already running with PID $(cat $PID_PATH_NAME)"
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- echo "$SERVICE_NAME starting ..."
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- -h)
- echo "Usage: email-monitor.sh"
-
- echo "command options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Email Monitor under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Daemon mode commands (use with -d):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- ;;
- esac
-done
-
-# If in daemon mode but no daemon command specified, show error
-if [ "$DAEMON_MODE" = true ]; then
- echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
- echo "Use -h for help"
- exit 1
-fi
-# Run in foreground mode
-java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/distribution/src/main/resources/distribution/bin/parser-wm.sh b/modules/distribution/src/main/resources/distribution/bin/parser-wm.sh
old mode 100644
new mode 100755
index c0d1e233ae..f451c6dabb
--- a/modules/distribution/src/main/resources/distribution/bin/parser-wm.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/parser-wm.sh
@@ -18,149 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="parser-wm"
MAIN_CLASS="org.apache.airavata.helix.impl.workflow.ParserWorkflowManager"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-LOGO=true
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# parse command arguments
-while [ $# -gt 0 ]; do
- case $1 in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME ..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started with PID $(cat $PID_PATH_NAME)"
- else
- echo "$SERVICE_NAME is already running with PID $(cat $PID_PATH_NAME)"
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- echo "$SERVICE_NAME starting ..."
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- -h)
- echo "Usage: parser-wm.sh"
-
- echo "command options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Parser Workflow Manager under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Daemon mode commands (use with -d):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- ;;
- esac
-done
-
-# If in daemon mode but no daemon command specified, show error
-if [ "$DAEMON_MODE" = true ]; then
- echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
- echo "Use -h for help"
- exit 1
-fi
-# Run in foreground mode
-java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/distribution/src/main/resources/distribution/bin/participant.sh b/modules/distribution/src/main/resources/distribution/bin/participant.sh
old mode 100644
new mode 100755
index 80c3cea70f..2f8730c743
--- a/modules/distribution/src/main/resources/distribution/bin/participant.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/participant.sh
@@ -18,149 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="participant"
MAIN_CLASS="org.apache.airavata.helix.impl.participant.GlobalParticipant"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-LOGO=true
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# parse command arguments
-while [ $# -gt 0 ]; do
- case $1 in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME ..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started with PID $(cat $PID_PATH_NAME)"
- else
- echo "$SERVICE_NAME is already running with PID $(cat $PID_PATH_NAME)"
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- echo "$SERVICE_NAME starting ..."
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- -h)
- echo "Usage: participant.sh"
-
- echo "command options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Helix Participant under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Daemon mode commands (use with -d):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- ;;
- esac
-done
-
-# If in daemon mode but no daemon command specified, show error
-if [ "$DAEMON_MODE" = true ]; then
- echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
- echo "Use -h for help"
- exit 1
-fi
-# Run in foreground mode
-java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/distribution/src/main/resources/distribution/bin/post-wm.sh b/modules/distribution/src/main/resources/distribution/bin/post-wm.sh
old mode 100644
new mode 100755
index f290dd925b..6d867cdcba
--- a/modules/distribution/src/main/resources/distribution/bin/post-wm.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/post-wm.sh
@@ -18,149 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="post-wm"
MAIN_CLASS="org.apache.airavata.helix.impl.workflow.PostWorkflowManager"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-LOGO=true
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# parse command arguments
-while [ $# -gt 0 ]; do
- case $1 in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME ..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started with PID $(cat $PID_PATH_NAME)"
- else
- echo "$SERVICE_NAME is already running with PID $(cat $PID_PATH_NAME)"
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- echo "$SERVICE_NAME starting ..."
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- -h)
- echo "Usage: post-wm.sh"
-
- echo "command options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Post Workflow Manager under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Daemon mode commands (use with -d):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- ;;
- esac
-done
-
-# If in daemon mode but no daemon command specified, show error
-if [ "$DAEMON_MODE" = true ]; then
- echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
- echo "Use -h for help"
- exit 1
-fi
-# Run in foreground mode
-java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/distribution/src/main/resources/distribution/bin/pre-wm.sh b/modules/distribution/src/main/resources/distribution/bin/pre-wm.sh
old mode 100644
new mode 100755
index 7ba5896444..c8f1dc3bab
--- a/modules/distribution/src/main/resources/distribution/bin/pre-wm.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/pre-wm.sh
@@ -18,149 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="pre-wm"
MAIN_CLASS="org.apache.airavata.helix.impl.workflow.PreWorkflowManager"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-LOGO=true
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# parse command arguments
-while [ $# -gt 0 ]; do
- case $1 in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME ..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started with PID $(cat $PID_PATH_NAME)"
- else
- echo "$SERVICE_NAME is already running with PID $(cat $PID_PATH_NAME)"
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- echo "$SERVICE_NAME starting ..."
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- -h)
- echo "Usage: pre-wm.sh"
-
- echo "command options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Pre Workflow Manager under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Daemon mode commands (use with -d):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- ;;
- esac
-done
-
-# If in daemon mode but no daemon command specified, show error
-if [ "$DAEMON_MODE" = true ]; then
- echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
- echo "Use -h for help"
- exit 1
-fi
-# Run in foreground mode
-java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/distribution/src/main/resources/distribution/bin/realtime-monitor.sh b/modules/distribution/src/main/resources/distribution/bin/realtime-monitor.sh
old mode 100644
new mode 100755
index 8389c321bd..347fd24a21
--- a/modules/distribution/src/main/resources/distribution/bin/realtime-monitor.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/realtime-monitor.sh
@@ -18,149 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="realtime-monitor"
MAIN_CLASS="org.apache.airavata.monitor.realtime.RealtimeMonitor"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-LOGO=true
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# parse command arguments
-while [ $# -gt 0 ]; do
- case $1 in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME ..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started with PID $(cat $PID_PATH_NAME)"
- else
- echo "$SERVICE_NAME is already running with PID $(cat $PID_PATH_NAME)"
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- echo "$SERVICE_NAME starting ..."
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is not running ..."
- fi
- exit 0
- else
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- fi
- ;;
- -h)
- echo "Usage: realtime-monitor.sh"
-
- echo "command options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Realtime Monitor under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Daemon mode commands (use with -d):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} $1"
- shift
- ;;
- esac
-done
-
-# If in daemon mode but no daemon command specified, show error
-if [ "$DAEMON_MODE" = true ]; then
- echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
- echo "Use -h for help"
- exit 1
-fi
-# Run in foreground mode
-java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} ${EXTRA_ARGS}
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/distribution/src/main/resources/distribution/bin/setenv.sh b/modules/distribution/src/main/resources/distribution/bin/setenv.sh
index 98c9836753..59cc88d4d2 100755
--- a/modules/distribution/src/main/resources/distribution/bin/setenv.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/setenv.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,32 +17,126 @@
# specific language governing permissions and limitations
# under the License.
-# resolve links - $0 may be a softlink
+# Resolve symlinks to get the real script location
PRG="$0"
-
-while [ -h "$PRG" ]; do
- ls=$(ls -ld "$PRG")
- link=$(expr "$ls" : '.*-> \(.*\)$')
- if expr "$link" : '.*/.*' >/dev/null; then
- PRG="$link"
- else
- PRG=$(dirname "$PRG")/"$link"
- fi
+while [ -L "$PRG" ]; do
+ PRG=$(readlink "$PRG")
done
-
PRGDIR=$(dirname "$PRG")
-# Only set AIRAVATA_HOME if not already set
-[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=$(
- cd "$PRGDIR/.."
- pwd
-)
+# Set AIRAVATA_HOME if not already set
+[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=$(cd "$PRGDIR/.." && pwd)
-AIRAVATA_CLASSPATH=""
+# Build CLASSPATH from all JAR files
+CLASSPATH=$(printf "%s:" "$AIRAVATA_HOME"/lib/*.jar)
+CLASSPATH=${CLASSPATH%:} # Remove trailing colon
-for f in "$AIRAVATA_HOME"/lib/*.jar; do
- AIRAVATA_CLASSPATH="$AIRAVATA_CLASSPATH":$f
-done
+export AIRAVATA_HOME CLASSPATH
+
+# Common function to run Airavata services
+# Usage: run_service <service_name> <main_class> <java_opts>
+run_service() {
+ local SERVICE_NAME="$1" MAIN_CLASS="$2" JAVA_OPTS="$3"
+ local CWD="$PWD" PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
+ local DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
+ local LOG_FILE="$DEFAULT_LOG_FILE" DAEMON_MODE=false EXTRA_ARGS=""
+
+ # Help text
+ local HELP_TEXT="Usage: ${SERVICE_NAME}.sh
+
+command options:
+ -d Run in daemon mode
+ -xdebug Start ${SERVICE_NAME} under JPDA debugger
+ -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)
+ -h Display this help and exit
+
+Daemon mode commands (use with -d):
+ start Start server in daemon mode
+ stop Stop server running in daemon mode
+ restart Restart server in daemon mode"
+
+ cd "${AIRAVATA_HOME}/bin"
+
+ # Helper function to stop daemon process
+ stop_daemon() {
+ if [[ -f "$PID_PATH_NAME" ]]; then
+ local PID=$(cat "$PID_PATH_NAME")
+ echo "$SERVICE_NAME stopping..."
+ kill "$PID"
+
+ local retry=0
+ while kill -0 "$PID" 2>/dev/null && ((retry++ < 20)); do
+ echo "[PID: $PID] Waiting for process to stop..."
+ sleep 1
+ done
+
+ if kill -0 "$PID" 2>/dev/null; then
+ echo "[PID: $PID] Forcefully killing non-responsive process..."
+ kill -9 "$PID"
+ fi
+
+ echo "$SERVICE_NAME is now stopped."
+ rm "$PID_PATH_NAME"
+ return 0
+ else
+ echo "$SERVICE_NAME is not running."
+ return 1
+ fi
+ }
+
+ # Helper function to start daemon process
+ start_daemon() {
+ echo "Starting $SERVICE_NAME ..."
+ if [[ ! -f "$PID_PATH_NAME" ]]; then
+ nohup java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" "$@" >"$LOG_FILE" 2>&1 &
+ echo $! >"$PID_PATH_NAME"
+ echo "$SERVICE_NAME now running: PID $(cat "$PID_PATH_NAME")"
+ else
+ echo "$SERVICE_NAME already running: PID $(cat "$PID_PATH_NAME")"
+ fi
+ }
+
+ # Parse command arguments
+ while (($# > 0)); do
+ case "$1" in
+ -d) DAEMON_MODE=true ;;
+ -xdebug) JAVA_OPTS+=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000" ;;
+ -log)
+ shift
+ LOG_FILE="$1"
+ [[ "$LOG_FILE" != /* ]] && LOG_FILE="${CWD}/${LOG_FILE}"
+ ;;
+ start | stop | restart)
+ if [[ "$DAEMON_MODE" == true ]]; then
+ case "$1" in
+ start) start_daemon "$@" ;;
+ stop) stop_daemon ;;
+ restart)
+ stop_daemon
+ start_daemon "$@"
+ ;;
+ esac
+ exit 0
+ else
+ EXTRA_ARGS+=" $1"
+ fi
+ ;;
+ -h)
+ echo "$HELP_TEXT"
+ exit 0
+ ;;
+ *) EXTRA_ARGS+=" $1" ;;
+ esac
+ shift
+ done
+
+ # Validate daemon mode usage
+ if [[ "$DAEMON_MODE" == true ]]; then
+ echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
+ echo "Use -h for help"
+ exit 1
+ fi
-export AIRAVATA_HOME
-export AIRAVATA_CLASSPATH
+ # Run in foreground mode
+ java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" $EXTRA_ARGS
+}
diff --git a/modules/distribution/src/main/resources/distribution/bin/sharing-registry.sh b/modules/distribution/src/main/resources/distribution/bin/sharing-registry.sh
old mode 100644
new mode 100755
index 4d16828dc2..9ce01762ae
--- a/modules/distribution/src/main/resources/distribution/bin/sharing-registry.sh
+++ b/modules/distribution/src/main/resources/distribution/bin/sharing-registry.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -18,75 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="sharing-registry"
MAIN_CLASS="org.apache.airavata.sharing.registry.server.ServerMain"
+JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-cd $SHARING_REGISTRY_HOME/bin
-
-IS_DAEMON_MODE=false
-SHARING_REGISTRY_COMMAND=""
-STOP=false
-FORCE=false
-JAVA_OPTS=""
-
-for var in "$@"; do
- case $var in
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=8000"
- shift
- ;;
- start)
- IS_DAEMON_MODE=true
- shift
- ;;
- stop)
- STOP=true
- SHARING_REGISTRY_COMMAND="$
- SHARING_REGISTRY_COMMAND $var"
- shift
- ;;
- -h)
- echo "Usage: sharing-registry.sh [command-options]"
- echo "command options:"
- echo " start Start server in daemon mode"
- echo " stop Stop server."
- echo " -xdebug Start Sharing Registry Server under JPDA debugger"
- echo " -h Display this help and exit"
- shift
- exit 0
- ;;
- *)
- SHARING_REGISTRY_COMMAND="$SHARING_REGISTRY_COMMAND $var"
- shift
- ;;
- esac
-done
-
-if $STOP; then
- 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[2]}..."
- out=$(kill -9 ${f_split[2]} 2>&1)
- if [ -z "$out" ]; then
- echo "done"
- else
- echo "failed (REASON: $out)"
- fi
- echo -n " Removing process file..."
- out=$(rm $f 2>&1)
- if [ -z "$out" ]; then
- echo "done"
- else
- echo "failed (REASON: $out)"
- fi
- done
-else
- if $IS_DAEMON_MODE; then
- echo "Starting ${SERVICE_NAME} in daemon mode..."
- $JAVA_HOME/bin/java ${JAVA_OPTS} -classpath "$SHARING_REGISTRY_CLASSPATH" ${MAIN_CLASS} $* >$LOG_FILE 2>&1 &
- else
- $JAVA_HOME/bin/java ${JAVA_OPTS} -classpath "$SHARING_REGISTRY_CLASSPATH" ${MAIN_CLASS} $*
- fi
-fi
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/distribution/src/main/resources/distribution/bin/start-network-server.sh b/modules/distribution/src/main/resources/distribution/bin/start-network-server.sh
deleted file mode 100644
index b1204ab6f4..0000000000
--- a/modules/distribution/src/main/resources/distribution/bin/start-network-server.sh
+++ /dev/null
@@ -1,180 +0,0 @@
-#!/bin/sh
-
-# 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.
-
-. $(dirname $0)/setenv.sh
-SERVICE_NAME="network-server"
-MAIN_CLASS="org.apache.derby.drda.NetworkServerControl"
-
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-
-if [ -n "$derby_common_debug" ]; then
- set -x
-fi
-
-# OS specific support. $var _must_ be set to either true or false.
-cygwin=false
-darwin=false
-case "$(uname)" in
-CYGWIN*) cygwin=true ;;
-Darwin*)
- darwin=true
- if [ -z "$JAVA_HOME" ]; then
- JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Home
- fi
- ;;
-esac
-
-if [ -z "$DERBY_HOME" -o ! -d "$DERBY_HOME" ]; then
- ## resolve links - $0 may be a link to derby's home
- PRG="$0"
- progname=$(basename "$0")
-
- # need this for relative symlinks
- while [ -h "$PRG" ]; do
- ls=$(ls -ld "$PRG")
- link=$(expr "$ls" : '.*-> \(.*\)$')
- if expr "$link" : '/.*' >/dev/null; then
- PRG="$link"
- else
- PRG=$(dirname "$PRG")"/$link"
- fi
- done
-
- DERBY_HOME=$(dirname "$PRG")/..
-
- # make it fully qualified
- DERBY_HOME=$(cd "$DERBY_HOME" && pwd)
-fi
-
-# For Cygwin, ensure paths are in UNIX format before anything is touched
-if $cygwin; then
- [ -n "$DERBY_HOME" ] &&
- DERBY_HOME=$(cygpath --unix "$DERBY_HOME")
- [ -n "$JAVA_HOME" ] &&
- JAVA_HOME=$(cygpath --unix "$JAVA_HOME")
-fi
-
-# set DERBY_LIB location
-DERBY_LIB="${DERBY_HOME}/lib"
-
-if [ -z "$JAVACMD" ]; then
- if [ -n "$JAVA_HOME" ]; then
- if [ -x "$JAVA_HOME/jre/sh/java" ]; then
- # IBM's JDK on AIX uses strange locations for the executables
- JAVACMD="$JAVA_HOME/jre/sh/java"
- else
- JAVACMD="$JAVA_HOME/bin/java"
- fi
- else
- JAVACMD=$(which java 2>/dev/null)
- if [ -z "$JAVACMD" ]; then
- JAVACMD=java
- fi
- fi
-fi
-
-if [ ! -x "$JAVACMD" ]; then
- echo "Error: JAVA_HOME is not defined correctly."
- echo " We cannot execute $JAVACMD"
- exit 1
-fi
-
-# set local classpath, don't overwrite the user's
-LOCALCLASSPATH=$DERBY_LIB/derby.jar:$DERBY_LIB/derbynet.jar:$DERBY_LIB/derbytools.jar:$DERBY_LIB/derbyclient.jar
-
-# if CLASSPATH_OVERRIDE env var is set, LOCALCLASSPATH will be
-# user CLASSPATH first and derby-found jars after.
-# In that case, the user CLASSPATH will override derby-found jars
-#
-# if CLASSPATH_OVERRIDE is not set, we'll have the normal behaviour
-# with derby-found jars first and user CLASSPATH after
-if [ -n "$CLASSPATH" ]; then
- # merge local and specified classpath
- if [ -z "$LOCALCLASSPATH" ]; then
- LOCALCLASSPATH="$CLASSPATH"
- elif [ -n "$CLASSPATH_OVERRIDE" ]; then
- LOCALCLASSPATH="$CLASSPATH:$LOCALCLASSPATH"
- else
- LOCALCLASSPATH="$LOCALCLASSPATH:$CLASSPATH"
- fi
-
- # remove class path from launcher -cp option
- CLASSPATH=""
-fi
-
-# For Cygwin, switch paths to appropriate format before running java
-# For PATHs convert to unix format first, then to windows format to ensure
-# both formats are supported. Probably this will fail on directories with ;
-# in the name in the path. Let's assume that paths containing ; are more
-# rare than windows style paths on cygwin.
-if $cygwin; then
- if [ "$OS" = "Windows_NT" ] && cygpath -m . >/dev/null 2>/dev/null; then
- format=mixed
- else
- format=windows
- fi
- DERBY_HOME=$(cygpath --$format "$DERBY_HOME")
- DERBY_LIB=$(cygpath --$format "$DERBY_LIB")
- if [ -n "$JAVA_HOME" ]; then
- JAVA_HOME=$(cygpath --$format "$JAVA_HOME")
- fi
- LCP_TEMP=$(cygpath --path --unix "$LOCALCLASSPATH")
- LOCALCLASSPATH=$(cygpath --path --$format "$LCP_TEMP")
- if [ -n "$CLASSPATH" ]; then
- CP_TEMP=$(cygpath --path --unix "$CLASSPATH")
- CLASSPATH=$(cygpath --path --$format "$CP_TEMP")
- fi
- CYGHOME=$(cygpath --$format "$HOME")
-fi
-
-# add a second backslash to variables terminated by a backslash under cygwin
-if $cygwin; then
- case "$DERBY_HOME" in
- *\\)
- DERBY_HOME="$DERBY_HOME\\"
- ;;
- esac
- case "$CYGHOME" in
- *\\)
- CYGHOME="$CYGHOME\\"
- ;;
- esac
- case "$LOCALCLASSPATH" in
- *\\)
- LOCALCLASSPATH="$LOCALCLASSPATH\\"
- ;;
- esac
- case "$CLASSPATH" in
- *\\)
- CLASSPATH="$CLASSPATH\\"
- ;;
- esac
-fi
-
-# Readjust classpath for MKS
-# expr match
-if [ \( "$(expr $SHELL : '.*sh.exe$')" -gt 0 \) -a \( "$cygwin" = "false" \) ]; then
- LOCALCLASSPATH=$(echo $LOCALCLASSPATH | sed -E 's/([\d\w]*):([\d\w]*)/\1;\2/g
-')
-fi
-
-derby_exec_command="exec \"$JAVACMD\" $DERBY_OPTS -classpath \"$LOCALCLASSPATH\" ${MAIN_CLASS} start $@"
-eval $derby_exec_command
diff --git a/modules/file-server/src/main/resources/distribution/bin/file-service.sh b/modules/file-server/src/main/resources/distribution/bin/file-service.sh
index 18e744c933..e380ac51db 100644
--- a/modules/file-server/src/main/resources/distribution/bin/file-service.sh
+++ b/modules/file-server/src/main/resources/distribution/bin/file-service.sh
@@ -17,171 +17,10 @@
# specific language governing permissions and limitations
# under the License.
-. `dirname $0`/setenv.sh
+. $(dirname $0)/setenv.sh
+
SERVICE_NAME="file-service"
MAIN_CLASS="org.apache.airavata.file.server.FileServerApplication"
+JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml -Dspring.config.location=${AIRAVATA_HOME}/conf/"
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
-JAVA_OPTS="-Dspring.config.location=${AIRAVATA_HOME}/conf/ -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# Function to start the service
-start_service() {
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME in daemon mode..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is already running ..."
- fi
- else
- echo "Starting $SERVICE_NAME in interactive mode..."
- java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $*
- fi
-}
-
-# Function to stop the service
-stop_service() {
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
-}
-
-# Function to restart the service
-restart_service() {
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- fi
- start_service $*
-}
-
-# Function to show help
-show_help() {
- echo "Usage: file-service.sh [options] [command]"
- echo ""
- echo "Commands (daemon mode only):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- echo ""
- echo "Options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start File Service under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Examples:"
- echo " file-service.sh # Run in interactive mode"
- echo " file-service.sh -d start # Start in daemon mode"
- echo " file-service.sh -d stop # Stop daemon"
- echo " file-service.sh -d restart # Restart daemon"
- echo " file-service.sh -xdebug # Run with debugger in interactive mode"
-}
-
-# parse command arguments
-for var in "$@"; do
- case ${var} in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- start_service $*
- exit 0
- else
- echo "Error: 'start' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- stop_service
- exit 0
- else
- echo "Error: 'stop' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- restart_service $*
- exit 0
- else
- echo "Error: 'restart' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- -h)
- show_help
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} ${var}"
- shift
- ;;
- esac
-done
-
-# If no specific command was given, run in interactive mode
-if [ "$DAEMON_MODE" = false ]; then
- java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $*
-fi
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/file-server/src/main/resources/distribution/bin/setenv.sh b/modules/file-server/src/main/resources/distribution/bin/setenv.sh
index 3f1d7632bf..59cc88d4d2 100644
--- a/modules/file-server/src/main/resources/distribution/bin/setenv.sh
+++ b/modules/file-server/src/main/resources/distribution/bin/setenv.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,30 +17,126 @@
# specific language governing permissions and limitations
# under the License.
-# resolve links - $0 may be a softlink
+# Resolve symlinks to get the real script location
PRG="$0"
-
-while [ -h "$PRG" ]; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '.*/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`/"$link"
- fi
+while [ -L "$PRG" ]; do
+ PRG=$(readlink "$PRG")
done
+PRGDIR=$(dirname "$PRG")
-PRGDIR=`dirname "$PRG"`
+# Set AIRAVATA_HOME if not already set
+[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=$(cd "$PRGDIR/.." && pwd)
-# Only set AIRAVATA_HOME if not already set
-[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=`cd "$PRGDIR/.." ; pwd`
+# Build CLASSPATH from all JAR files
+CLASSPATH=$(printf "%s:" "$AIRAVATA_HOME"/lib/*.jar)
+CLASSPATH=${CLASSPATH%:} # Remove trailing colon
-AIRAVATA_CLASSPATH=""
+export AIRAVATA_HOME CLASSPATH
-for f in "$AIRAVATA_HOME"/lib/*.jar
-do
- AIRAVATA_CLASSPATH="$AIRAVATA_CLASSPATH":$f
-done
+# Common function to run Airavata services
+# Usage: run_service <service_name> <main_class> <java_opts>
+run_service() {
+ local SERVICE_NAME="$1" MAIN_CLASS="$2" JAVA_OPTS="$3"
+ local CWD="$PWD" PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
+ local DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
+ local LOG_FILE="$DEFAULT_LOG_FILE" DAEMON_MODE=false EXTRA_ARGS=""
+
+ # Help text
+ local HELP_TEXT="Usage: ${SERVICE_NAME}.sh
+
+command options:
+ -d Run in daemon mode
+ -xdebug Start ${SERVICE_NAME} under JPDA debugger
+ -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)
+ -h Display this help and exit
+
+Daemon mode commands (use with -d):
+ start Start server in daemon mode
+ stop Stop server running in daemon mode
+ restart Restart server in daemon mode"
+
+ cd "${AIRAVATA_HOME}/bin"
+
+ # Helper function to stop daemon process
+ stop_daemon() {
+ if [[ -f "$PID_PATH_NAME" ]]; then
+ local PID=$(cat "$PID_PATH_NAME")
+ echo "$SERVICE_NAME stopping..."
+ kill "$PID"
+
+ local retry=0
+ while kill -0 "$PID" 2>/dev/null && ((retry++ < 20)); do
+ echo "[PID: $PID] Waiting for process to stop..."
+ sleep 1
+ done
+
+ if kill -0 "$PID" 2>/dev/null; then
+ echo "[PID: $PID] Forcefully killing non-responsive process..."
+ kill -9 "$PID"
+ fi
+
+ echo "$SERVICE_NAME is now stopped."
+ rm "$PID_PATH_NAME"
+ return 0
+ else
+ echo "$SERVICE_NAME is not running."
+ return 1
+ fi
+ }
+
+ # Helper function to start daemon process
+ start_daemon() {
+ echo "Starting $SERVICE_NAME ..."
+ if [[ ! -f "$PID_PATH_NAME" ]]; then
+ nohup java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" "$@" >"$LOG_FILE" 2>&1 &
+ echo $! >"$PID_PATH_NAME"
+ echo "$SERVICE_NAME now running: PID $(cat "$PID_PATH_NAME")"
+ else
+ echo "$SERVICE_NAME already running: PID $(cat "$PID_PATH_NAME")"
+ fi
+ }
+
+ # Parse command arguments
+ while (($# > 0)); do
+ case "$1" in
+ -d) DAEMON_MODE=true ;;
+ -xdebug) JAVA_OPTS+=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000" ;;
+ -log)
+ shift
+ LOG_FILE="$1"
+ [[ "$LOG_FILE" != /* ]] && LOG_FILE="${CWD}/${LOG_FILE}"
+ ;;
+ start | stop | restart)
+ if [[ "$DAEMON_MODE" == true ]]; then
+ case "$1" in
+ start) start_daemon "$@" ;;
+ stop) stop_daemon ;;
+ restart)
+ stop_daemon
+ start_daemon "$@"
+ ;;
+ esac
+ exit 0
+ else
+ EXTRA_ARGS+=" $1"
+ fi
+ ;;
+ -h)
+ echo "$HELP_TEXT"
+ exit 0
+ ;;
+ *) EXTRA_ARGS+=" $1" ;;
+ esac
+ shift
+ done
+
+ # Validate daemon mode usage
+ if [[ "$DAEMON_MODE" == true ]]; then
+ echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
+ echo "Use -h for help"
+ exit 1
+ fi
-export AIRAVATA_HOME
-export AIRAVATA_CLASSPATH
\ No newline at end of file
+ # Run in foreground mode
+ java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" $EXTRA_ARGS
+}
diff --git a/modules/research-framework/research-service/src/main/resources/distribution/bin/research-service.sh b/modules/research-framework/research-service/src/main/resources/distribution/bin/research-service.sh
index 6aad39fca9..fdda7eaa78 100755
--- a/modules/research-framework/research-service/src/main/resources/distribution/bin/research-service.sh
+++ b/modules/research-framework/research-service/src/main/resources/distribution/bin/research-service.sh
@@ -18,170 +18,9 @@
# under the License.
. $(dirname $0)/setenv.sh
+
SERVICE_NAME="research-service"
MAIN_CLASS="org.apache.airavata.research.service.ResearchServiceApplication"
+JAVA_OPTS="-Dairavata.config.dir=${AIRAVATA_HOME}/conf -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml -Dairavata.server.truststore.path=${AIRAVATA_HOME}/conf/airavata.jks -Dspring.config.location=${AIRAVATA_HOME}/conf/"
-# Capture user's working dir before changing directory
-CWD="$PWD"
-cd ${AIRAVATA_HOME}/bin
-LOGO_FILE="${AIRAVATA_HOME}/logo.txt"
-
-JAVA_OPTS="-Dairavata.server.truststore.path=${AIRAVATA_HOME}/conf/airavata.jks -Dspring.config.location=${AIRAVATA_HOME}/conf/ -Dairavata.home=${AIRAVATA_HOME} -Dlog4j.configurationFile=file:${AIRAVATA_HOME}/conf/log4j2.xml"
-AIRAVATA_COMMAND=""
-EXTRA_ARGS=""
-SERVERS=""
-IS_SUBSET=false
-SUBSET=""
-DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
-LOG_FILE=$DEFAULT_LOG_FILE
-DAEMON_MODE=false
-PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
-
-# Function to start the service
-start_service() {
- if [ "$DAEMON_MODE" = true ]; then
- echo "Starting $SERVICE_NAME in daemon mode..."
- if [ ! -f $PID_PATH_NAME ]; then
- nohup java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $* >$LOG_FILE 2>&1 &
- echo $! >$PID_PATH_NAME
- echo "$SERVICE_NAME started ..."
- else
- echo "$SERVICE_NAME is already running ..."
- fi
- else
- echo "Starting $SERVICE_NAME in interactive mode..."
- java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $*
- fi
-}
-
-# Function to stop the service
-stop_service() {
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- else
- echo "$SERVICE_NAME is not running ..."
- fi
-}
-
-# Function to restart the service
-restart_service() {
- if [ -f $PID_PATH_NAME ]; then
- PID=$(cat $PID_PATH_NAME)
- echo "$SERVICE_NAME stopping ..."
- kill $PID
- RETRY=0
- while kill -0 $PID 2>/dev/null; do
- echo "Waiting for the process $PID to be stopped"
- RETRY=$(expr ${RETRY} + 1)
- if [ "${RETRY}" -gt "20" ]; then
- echo "Forcefully killing the process as it is not responding ..."
- kill -9 $PID
- fi
- sleep 1
- done
- echo "$SERVICE_NAME stopped ..."
- rm $PID_PATH_NAME
- fi
- start_service $*
-}
-
-# Function to show help
-show_help() {
- echo "Usage: research-service.sh [options] [command]"
- echo ""
- echo "Commands (daemon mode only):"
- echo " start Start server in daemon mode"
- echo " stop Stop server running in daemon mode"
- echo " restart Restart server in daemon mode"
- echo ""
- echo "Options:"
- echo " -d Run in daemon mode"
- echo " -xdebug Start Research Service under JPDA debugger"
- echo " -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)"
- echo " -h Display this help and exit"
- echo ""
- echo "Examples:"
- echo " research-service.sh # Run in interactive mode"
- echo " research-service.sh -d start # Start in daemon mode"
- echo " research-service.sh -d stop # Stop daemon"
- echo " research-service.sh -d restart # Restart daemon"
- echo " research-service.sh -xdebug # Run with debugger in interactive mode"
-}
-
-# parse command arguments
-for var in "$@"; do
- case ${var} in
- -d)
- DAEMON_MODE=true
- shift
- ;;
- -xdebug)
- AIRAVATA_COMMAND="${AIRAVATA_COMMAND}"
- JAVA_OPTS="$JAVA_OPTS -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000"
- shift
- ;;
- -log)
- shift
- LOG_FILE="$1"
- shift
- # If relative path, expand to absolute path using the user's $CWD
- if [ -z "$(echo "$LOG_FILE" | egrep "^/")" ]; then
- LOG_FILE="${CWD}/${LOG_FILE}"
- fi
- ;;
- start)
- if [ "$DAEMON_MODE" = true ]; then
- start_service $*
- exit 0
- else
- echo "Error: 'start' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- stop)
- if [ "$DAEMON_MODE" = true ]; then
- stop_service
- exit 0
- else
- echo "Error: 'stop' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- restart)
- if [ "$DAEMON_MODE" = true ]; then
- restart_service $*
- exit 0
- else
- echo "Error: 'restart' command requires daemon mode (-d flag)"
- exit 1
- fi
- ;;
- -h)
- show_help
- exit 0
- ;;
- *)
- EXTRA_ARGS="${EXTRA_ARGS} ${var}"
- shift
- ;;
- esac
-done
-
-# If no specific command was given, run in interactive mode
-if [ "$DAEMON_MODE" = false ]; then
- java ${JAVA_OPTS} -classpath "${AIRAVATA_CLASSPATH}" ${MAIN_CLASS} ${AIRAVATA_COMMAND} $*
-fi
+run_service "$SERVICE_NAME" "$MAIN_CLASS" "$JAVA_OPTS" "$@"
diff --git a/modules/research-framework/research-service/src/main/resources/distribution/bin/setenv.sh b/modules/research-framework/research-service/src/main/resources/distribution/bin/setenv.sh
index 3f1d7632bf..59cc88d4d2 100755
--- a/modules/research-framework/research-service/src/main/resources/distribution/bin/setenv.sh
+++ b/modules/research-framework/research-service/src/main/resources/distribution/bin/setenv.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
@@ -17,30 +17,126 @@
# specific language governing permissions and limitations
# under the License.
-# resolve links - $0 may be a softlink
+# Resolve symlinks to get the real script location
PRG="$0"
-
-while [ -h "$PRG" ]; do
- ls=`ls -ld "$PRG"`
- link=`expr "$ls" : '.*-> \(.*\)$'`
- if expr "$link" : '.*/.*' > /dev/null; then
- PRG="$link"
- else
- PRG=`dirname "$PRG"`/"$link"
- fi
+while [ -L "$PRG" ]; do
+ PRG=$(readlink "$PRG")
done
+PRGDIR=$(dirname "$PRG")
-PRGDIR=`dirname "$PRG"`
+# Set AIRAVATA_HOME if not already set
+[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=$(cd "$PRGDIR/.." && pwd)
-# Only set AIRAVATA_HOME if not already set
-[ -z "$AIRAVATA_HOME" ] && AIRAVATA_HOME=`cd "$PRGDIR/.." ; pwd`
+# Build CLASSPATH from all JAR files
+CLASSPATH=$(printf "%s:" "$AIRAVATA_HOME"/lib/*.jar)
+CLASSPATH=${CLASSPATH%:} # Remove trailing colon
-AIRAVATA_CLASSPATH=""
+export AIRAVATA_HOME CLASSPATH
-for f in "$AIRAVATA_HOME"/lib/*.jar
-do
- AIRAVATA_CLASSPATH="$AIRAVATA_CLASSPATH":$f
-done
+# Common function to run Airavata services
+# Usage: run_service <service_name> <main_class> <java_opts>
+run_service() {
+ local SERVICE_NAME="$1" MAIN_CLASS="$2" JAVA_OPTS="$3"
+ local CWD="$PWD" PID_PATH_NAME="${AIRAVATA_HOME}/bin/pid-${SERVICE_NAME}"
+ local DEFAULT_LOG_FILE="${AIRAVATA_HOME}/logs/${SERVICE_NAME}.log"
+ local LOG_FILE="$DEFAULT_LOG_FILE" DAEMON_MODE=false EXTRA_ARGS=""
+
+ # Help text
+ local HELP_TEXT="Usage: ${SERVICE_NAME}.sh
+
+command options:
+ -d Run in daemon mode
+ -xdebug Start ${SERVICE_NAME} under JPDA debugger
+ -log <LOG_FILE> Where to redirect stdout/stderr (defaults to $DEFAULT_LOG_FILE)
+ -h Display this help and exit
+
+Daemon mode commands (use with -d):
+ start Start server in daemon mode
+ stop Stop server running in daemon mode
+ restart Restart server in daemon mode"
+
+ cd "${AIRAVATA_HOME}/bin"
+
+ # Helper function to stop daemon process
+ stop_daemon() {
+ if [[ -f "$PID_PATH_NAME" ]]; then
+ local PID=$(cat "$PID_PATH_NAME")
+ echo "$SERVICE_NAME stopping..."
+ kill "$PID"
+
+ local retry=0
+ while kill -0 "$PID" 2>/dev/null && ((retry++ < 20)); do
+ echo "[PID: $PID] Waiting for process to stop..."
+ sleep 1
+ done
+
+ if kill -0 "$PID" 2>/dev/null; then
+ echo "[PID: $PID] Forcefully killing non-responsive process..."
+ kill -9 "$PID"
+ fi
+
+ echo "$SERVICE_NAME is now stopped."
+ rm "$PID_PATH_NAME"
+ return 0
+ else
+ echo "$SERVICE_NAME is not running."
+ return 1
+ fi
+ }
+
+ # Helper function to start daemon process
+ start_daemon() {
+ echo "Starting $SERVICE_NAME ..."
+ if [[ ! -f "$PID_PATH_NAME" ]]; then
+ nohup java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" "$@" >"$LOG_FILE" 2>&1 &
+ echo $! >"$PID_PATH_NAME"
+ echo "$SERVICE_NAME now running: PID $(cat "$PID_PATH_NAME")"
+ else
+ echo "$SERVICE_NAME already running: PID $(cat "$PID_PATH_NAME")"
+ fi
+ }
+
+ # Parse command arguments
+ while (($# > 0)); do
+ case "$1" in
+ -d) DAEMON_MODE=true ;;
+ -xdebug) JAVA_OPTS+=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,address=*:8000" ;;
+ -log)
+ shift
+ LOG_FILE="$1"
+ [[ "$LOG_FILE" != /* ]] && LOG_FILE="${CWD}/${LOG_FILE}"
+ ;;
+ start | stop | restart)
+ if [[ "$DAEMON_MODE" == true ]]; then
+ case "$1" in
+ start) start_daemon "$@" ;;
+ stop) stop_daemon ;;
+ restart)
+ stop_daemon
+ start_daemon "$@"
+ ;;
+ esac
+ exit 0
+ else
+ EXTRA_ARGS+=" $1"
+ fi
+ ;;
+ -h)
+ echo "$HELP_TEXT"
+ exit 0
+ ;;
+ *) EXTRA_ARGS+=" $1" ;;
+ esac
+ shift
+ done
+
+ # Validate daemon mode usage
+ if [[ "$DAEMON_MODE" == true ]]; then
+ echo "Error: Daemon mode (-d) requires one of: start, stop, restart"
+ echo "Use -h for help"
+ exit 1
+ fi
-export AIRAVATA_HOME
-export AIRAVATA_CLASSPATH
\ No newline at end of file
+ # Run in foreground mode
+ java $JAVA_OPTS -classpath "$CLASSPATH" "$MAIN_CLASS" $EXTRA_ARGS
+}