| 1 | #! /bin/sh |
|---|
| 2 | |
|---|
| 3 | # |
|---|
| 4 | # Kauri Runtime startup script for use during Kauri development |
|---|
| 5 | # meaning: there is no KAURI_HOME, Kauri artifacts are in dev's local Maven repo |
|---|
| 6 | # |
|---|
| 7 | |
|---|
| 8 | # You can use the following environment variables to customize the startup |
|---|
| 9 | # |
|---|
| 10 | # KAURI_CLI_CLASSPATH |
|---|
| 11 | # additional entries to be added to the classpath |
|---|
| 12 | # |
|---|
| 13 | # KAURI_JAVA_ARGS |
|---|
| 14 | # additional options to be passed to the java executable |
|---|
| 15 | # |
|---|
| 16 | # KAURI_DEBUG_ARGS |
|---|
| 17 | # can be used to define alternative Java debug arguments |
|---|
| 18 | # |
|---|
| 19 | # KAURI_DEBUG_SUSPEND_ARGS |
|---|
| 20 | # can be used to define alternative Java debug arguments for suspended mode |
|---|
| 21 | # |
|---|
| 22 | |
|---|
| 23 | # |
|---|
| 24 | # Disclaimer: this script is based on stuff from Apache Cocoon's 'cocoon.sh' script |
|---|
| 25 | # |
|---|
| 26 | |
|---|
| 27 | usage() |
|---|
| 28 | { |
|---|
| 29 | echo "Usage: $0 (action)" |
|---|
| 30 | echo "actions:" |
|---|
| 31 | echo " run Run the Kauri Runtime (default)" |
|---|
| 32 | echo " debug Run the Kauri Runtime with debug port 5005" |
|---|
| 33 | echo " debug-suspend Run the Kauri Runtime, suspend for debugger to connect on port 5005" |
|---|
| 34 | echo "" |
|---|
| 35 | echo "To see help options for Kauri, use $0 run -h" |
|---|
| 36 | echo "" |
|---|
| 37 | exit 1 |
|---|
| 38 | } |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | # ----- Handle action parameter ------------------------------------------------ |
|---|
| 42 | DEFAULT_ACTION="run" |
|---|
| 43 | ACTION="$1" |
|---|
| 44 | if [ -n "$ACTION" ] |
|---|
| 45 | then |
|---|
| 46 | shift |
|---|
| 47 | else |
|---|
| 48 | ACTION=$DEFAULT_ACTION |
|---|
| 49 | echo "$0: executing default action '$ACTION', use -h to see other actions" |
|---|
| 50 | fi |
|---|
| 51 | ARGS="$*" |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | # ----- Find out home dir of this script --------------------------------------- |
|---|
| 56 | |
|---|
| 57 | # |
|---|
| 58 | # Disclaimer: this is based on things seen in Ant's startup script |
|---|
| 59 | # |
|---|
| 60 | |
|---|
| 61 | ## resolve links - $0 may be a link to Kauri's home |
|---|
| 62 | PRG="$0" |
|---|
| 63 | progname=`basename "$0"` |
|---|
| 64 | |
|---|
| 65 | # need this for relative symlinks |
|---|
| 66 | while [ -h "$PRG" ] ; do |
|---|
| 67 | ls=`ls -ld "$PRG"` |
|---|
| 68 | link=`expr "$ls" : '.*-> \(.*\)$'` |
|---|
| 69 | if expr "$link" : '/.*' > /dev/null; then |
|---|
| 70 | PRG="$link" |
|---|
| 71 | else |
|---|
| 72 | PRG=`dirname "$PRG"`"/$link" |
|---|
| 73 | fi |
|---|
| 74 | done |
|---|
| 75 | |
|---|
| 76 | KAURI_SRC_HOME=`dirname "$PRG"` |
|---|
| 77 | |
|---|
| 78 | # make it fully qualified |
|---|
| 79 | KAURI_SRC_HOME=`cd "$KAURI_SRC_HOME" && pwd` |
|---|
| 80 | |
|---|
| 81 | |
|---|
| 82 | # ----- Verify and Set Required Environment Variables ------------------------- |
|---|
| 83 | if [ -z "$JAVA_HOME" ] ; then |
|---|
| 84 | echo "JAVA_HOME not set!" |
|---|
| 85 | exit 1 |
|---|
| 86 | fi |
|---|
| 87 | |
|---|
| 88 | LAUNCHER_JAR=$KAURI_SRC_HOME/core/kauri-runtime-launcher/target/kauri-runtime-launcher.jar |
|---|
| 89 | |
|---|
| 90 | [ ! -r "$LAUNCHER_JAR" ] \ |
|---|
| 91 | && echo "Launcher jar not found at $LAUNCHER_JAR" \ |
|---|
| 92 | && echo "Please build Kauri first using 'mvn install'" \ |
|---|
| 93 | && exit 1 |
|---|
| 94 | |
|---|
| 95 | CLASSPATH=$LAUNCHER_JAR |
|---|
| 96 | |
|---|
| 97 | # Only add KAURI_CLI_CLASSPATH when it is not empty, to avoid adding the working dir to |
|---|
| 98 | # the classpath by accident. |
|---|
| 99 | if [ ! -z "$KAURI_CLI_CLASSPATH" ] ; then |
|---|
| 100 | CLASSPATH=$CLASSPATH:$KAURI_CLI_CLASSPATH |
|---|
| 101 | fi |
|---|
| 102 | |
|---|
| 103 | export CLASSPATH |
|---|
| 104 | |
|---|
| 105 | if [ "$KAURI_DEBUG_ARGS" = "" ] ; then |
|---|
| 106 | KAURI_DEBUG_ARGS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005" |
|---|
| 107 | fi |
|---|
| 108 | |
|---|
| 109 | if [ "$KAURI_DEBUG_SUSPEND_ARGS" = "" ] ; then |
|---|
| 110 | KAURI_DEBUG_SUSPEND_ARGS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005" |
|---|
| 111 | fi |
|---|
| 112 | |
|---|
| 113 | # ----- Do the action ---------------------------------------------------------- |
|---|
| 114 | |
|---|
| 115 | case "$ACTION" in |
|---|
| 116 | run) |
|---|
| 117 | "$JAVA_HOME/bin/java" -Djava.awt.headless=true $KAURI_JAVA_ARGS org.kauriproject.launcher.RuntimeCliLauncher $@ |
|---|
| 118 | ;; |
|---|
| 119 | |
|---|
| 120 | debug) |
|---|
| 121 | "$JAVA_HOME/bin/java" -Djava.awt.headless=true $KAURI_JAVA_ARGS $KAURI_DEBUG_ARGS org.kauriproject.launcher.RuntimeCliLauncher $@ |
|---|
| 122 | ;; |
|---|
| 123 | |
|---|
| 124 | debug-suspend) |
|---|
| 125 | echo "Don't forget: you'll need to connect with a debugger for Kauri to start" |
|---|
| 126 | "$JAVA_HOME/bin/java" -Djava.awt.headless=true $KAURI_JAVA_ARGS $KAURI_DEBUG_SUSPEND_ARGS org.kauriproject.launcher.RuntimeCliLauncher $@ |
|---|
| 127 | ;; |
|---|
| 128 | |
|---|
| 129 | *) |
|---|
| 130 | usage |
|---|
| 131 | ;; |
|---|
| 132 | esac |
|---|
| 133 | |
|---|
| 134 | exit 0 |
|---|