directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lucasthei...@apache.org
Subject svn commit: r1592192 - /directory/apacheds/trunk/installers-maven-plugin/src/main/resources/org/apache/directory/server/installers/archive/apacheds.sh
Date Sat, 03 May 2014 12:28:05 GMT
Author: lucastheisen
Date: Sat May  3 12:28:04 2014
New Revision: 1592192

URL: http://svn.apache.org/r1592192
Log:
Updated apacheds.sh to detect apacheds root (rather than assuming the script was run from
the bin directory itself), provide start and stop methods, and added cygwin support.

Modified:
    directory/apacheds/trunk/installers-maven-plugin/src/main/resources/org/apache/directory/server/installers/archive/apacheds.sh

Modified: directory/apacheds/trunk/installers-maven-plugin/src/main/resources/org/apache/directory/server/installers/archive/apacheds.sh
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/installers-maven-plugin/src/main/resources/org/apache/directory/server/installers/archive/apacheds.sh?rev=1592192&r1=1592191&r2=1592192&view=diff
==============================================================================
--- directory/apacheds/trunk/installers-maven-plugin/src/main/resources/org/apache/directory/server/installers/archive/apacheds.sh
(original)
+++ directory/apacheds/trunk/installers-maven-plugin/src/main/resources/org/apache/directory/server/installers/archive/apacheds.sh
Sat May  3 12:28:04 2014
@@ -18,51 +18,100 @@
 #  under the License.
 #
 
-# Checking the number of parameters
-if [ $# -eq 0 ]
+# Detect ads home (http://stackoverflow.com/a/630387/516433)
+ADS_HOME="`dirname \"$0\"`"
+ADS_HOME="`(cd \"$ADS_HOME/..\" && pwd)`"
+if [ -z "$ADS_HOME" ]; then
+    exit 1;
+fi
+
+# OS sepecific support
+cygwin=false
+case "`uname`" in
+    CYGWIN*) cygwin=true
+esac
+
+# Checking the parameters
+ADS_INSTANCE_NAME=
+ADS_ACTION=
+if [ $# -eq 1 ]
 then
     # Using 'default' as default instance name
     ADS_INSTANCE_NAME="default"
-elif [ $# -eq 1 ]
+    ADS_ACTION=$1
+elif [ $# -eq 2 ]
 then
     # Getting the instance name from the arguments
     ADS_INSTANCE_NAME=$1
+    ADS_ACTION=$2
 else
     # Printing usage information
-    echo "Usage: apacheds.sh <instance name>"
+    echo "Usage: apacheds.sh [<instance name>] <action>"
     echo "If <instance name> is ommited, 'default' will be used."
+    echo "<action> is one of start, stop."
     exit 1
 fi
 
-# Printing instance information
-echo "Starting ApacheDS instance '$ADS_INSTANCE_NAME'..."
+# For cygwin, ensure paths or in unix format before touched
+if $cygwin; then
+    [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+    [ -n "$ADS_HOME" ] && ADS_HOME=`cygpath --unix "$ADS_HOME"`
+fi
 
-# Getting the fully qualified path to the script
-case $0 in 
-    /*) 
-        SCRIPT="$0" 
-        ;; 
-   ./*) 
-        SCRIPT="`pwd`/`echo $0 | sed -e 's/^[ ]*\.\///'`" 
-        ;; 
-     *) 
-        SCRIPT="`pwd`/`echo $0 | sed -e 's/^[ ]*//'`" 
-        ;; 
-esac 
-
-# Getting the working directory of the script
-ADS_PWD=`dirname $SCRIPT`/..
-
-# Building dynamically the classpath
-ADS_CP=
-for i in `ls $ADS_PWD/lib/`
-do
-  ADS_CP=${ADS_CP}:$ADS_PWD/lib/${i}
-done
+RUN_JAVA="$JAVA_HOME"/bin/java
 
-ADS_CONTROLS="-Dapacheds.controls="
+# Build the classpath (http://stackoverflow.com/a/4729899/516433)
+CLASSPATH=$(JARS=("$ADS_HOME"/lib/*.jar); IFS=:; echo "${JARS[*]}")
 
-ADS_EXTENDED_OPERATIONS="-Dapacheds.extendedOperations="
+mkdir -p "$ADS_HOME/instances/$ADS_INSTANCE_NAME/log"
+mkdir -p "$ADS_HOME/instances/$ADS_INSTANCE_NAME/run"
+ADS_OUT="$ADS_HOME/instances/$ADS_INSTANCE_NAME/log/apacheds.out"
+ADS_PID="$ADS_HOME/instances/$ADS_INSTANCE_NAME/run/apacheds.pid"
+
+# For cygwin, switch to windows paths before running
+if $cygwin; then
+    JAVA_HOME=`cygpath --absolute --windows "$JAVA_HOME"`
+    ADS_HOME=`cygpath --absolute --windows "$ADS_HOME"`
+    CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+fi
 
-# Launching ApacheDS
-java $JAVA_OPTS $ADS_CONTROLS $ADS_EXTENDED_OPERATIONS -Dlog4j.configuration=file:$ADS_PWD/instances/$ADS_INSTANCE_NAME/conf/log4j.properties
-Dapacheds.log.dir=$ADS_PWD/instances/$ADS_INSTANCE_NAME/log -cp $ADS_CP org.apache.directory.server.UberjarMain
$ADS_PWD/instances/$ADS_INSTANCE_NAME
\ No newline at end of file
+ADS_CONTROLS="-Dapacheds.controls=org.apache.directory.api.ldap.codec.controls.cascade.CascadeFactory,org.apache.directory.api.ldap.codec.controls.manageDsaIT.ManageDsaITFactory,org.apache.directory.api.ldap.codec.controls.search.entryChange.EntryChangeFactory,org.apache.directory.api.ldap.codec.controls.search.pagedSearch.PagedResultsFactory,org.apache.directory.api.ldap.codec.controls.search.persistentSearch.PersistentSearchFactory,org.apache.directory.api.ldap.codec.controls.search.subentries.SubentriesFactory,org.apache.directory.api.ldap.extras.controls.ppolicy_impl.PasswordPolicyFactory,org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncDoneValueFactory,org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncInfoValueFactory,org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncRequestValueFactory,org.apache.directory.api.ldap.extras.controls.syncrepl_impl.SyncStateValueFactory"
+
+ADS_EXTENDED_OPERATIONS="-Dapacheds.extendedOperations=org.apache.directory.api.ldap.extras.extended.ads_impl.cancel.CancelFactory,org.apache.directory.api.ldap.extras.extended.ads_impl.certGeneration.CertGenerationFactory,org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulShutdown.GracefulShutdownFactory,org.apache.directory.api.ldap.extras.extended.ads_impl.storedProcedure.StoredProcedureFactory,org.apache.directory.api.ldap.extras.extended.ads_impl.gracefulDisconnect.GracefulDisconnectFactory"
+
+if [ "$ADS_ACTION" = "start" ]; then
+    # Printing instance information
+    echo "Starting ApacheDS instance '$ADS_INSTANCE_NAME'..."
+
+    if [ -f "$ADS_PID" ]; then
+        PID=`cat "$ADS_PID"`
+        ps -p $PID > /dev/null 2>&1
+        if [ $? -eq 0 ]; then
+            echo "ApacheDS appears to still be running with PID $PID. Start aborted."
+            exit 1;
+        fi
+    fi
+
+    # Launching ApacheDS
+    eval "\"$RUN_JAVA\"" $JAVA_OPTS $ADS_CONTROLS $ADS_EXTENDED_OPERATIONS \
+        -Dlog4j.configuration="\"file:$ADS_HOME/instances/$ADS_INSTANCE_NAME/conf/log4j.properties\""
\
+        -Dapacheds.log.dir="\"$ADS_HOME/instances/$ADS_INSTANCE_NAME/log\"" \
+        -classpath "\"$CLASSPATH\"" \
+        org.apache.directory.server.UberjarMain "\"$ADS_HOME/instances/$ADS_INSTANCE_NAME\""
\
+        > "$ADS_OUT" 2>&1 "&"
+    echo $! > "$ADS_PID"
+elif [ "$ADS_ACTION" = "stop" ]; then
+    # Printing instance information
+    echo "Stopping ApacheDS instance '$ADS_INSTANCE_NAME'..."
+
+    if [ -f "$ADS_PID" ]; then
+        PID=`cat "$ADS_PID"`
+        kill -0 $PID > /dev/null 2>&1
+        if [ $? = 0 ]; then
+            kill $PID
+        fi
+        rm -f $ADS_PID > /dev/null 2>&1
+    else
+        echo "$ADS_PID not found"
+    fi
+fi



Mime
View raw message