5 if [[ "$unamestr" == 'Linux' ]]; then
7 elif [[ "$unamestr" == 'Darwin' ]]; then
11 if [[ $platform == 'linux' ]]; then
12 fullpath=`readlink -f $0`
14 if [[ -z ${JAVA_HOME} ]]; then
15 # Find the actual location of the Java launcher:
16 java_launcher=`which java`
17 java_launcher=`readlink -f "${java_launcher}"`
19 # Compute the Java home from the location of the Java launcher:
20 export JAVA_HOME="${java_launcher%/bin/java}"
22 elif [[ $platform == 'osx' ]]; then
24 cd `dirname "$TARGET_FILE"`
25 TARGET_FILE=`basename $TARGET_FILE`
27 # Iterate down a (possible) chain of symlinks
28 while [ -L "$TARGET_FILE" ]
30 TARGET_FILE=`readlink "$TARGET_FILE"`
31 cd `dirname "$TARGET_FILE"`
32 TARGET_FILE=`basename "$TARGET_FILE"`
35 # Compute the canonicalized name by finding the physical path
36 # for the directory we're in and appending the target file.
38 RESULT=$PHYS_DIR/$TARGET_FILE
41 [[ -z ${JAVA_HOME} ]] && [[ -x "/usr/libexec/java_home" ]] && export JAVA_HOME=`/usr/libexec/java_home -v 1.7`;
45 [[ -z ${JAVA_HOME} ]] && echo "Need to set JAVA_HOME environment variable" && exit -1;
46 [[ ! -x ${JAVA_HOME}/bin/java ]] && echo "Cannot find an executable \
47 JVM at path ${JAVA_HOME}/bin/java check your JAVA_HOME" && exit -1;
49 if [ -z ${ODL_BASEDIR} ]; then
50 basedir=`dirname "${fullpath}"`
52 basedir=${ODL_BASEDIR}
55 if [ -z ${ODL_DATADIR} ]; then
56 datadir=`dirname "${fullpath}"`
58 datadir=${ODL_DATADIR}
62 echo "Usage: $0 [-jmx] [-jmxport <num>] [-debug] [-debugsuspend] [-debugport <num>] [-start [<console port>]] [-stop] [-status] [-console] [-help] [-agentpath:<path to lib>] [<other args will automatically be used for the JVM>]"
66 if [ -z ${TMP} ]; then
67 pidfile="/tmp/opendaylight.PID"
69 pidfile="${TMP}/opendaylight.PID"
91 -debug) debug=1; shift ;;
92 -jmx) startjmx=1; shift ;;
93 -debugsuspend) debugsuspend=1; shift ;;
94 -debugport) shift; debugportread="$1"; if [[ "${debugportread}" =~ ^[0-9]+$ ]] ; then debugport=${debugportread}; shift; else echo "-debugport expects a number but was not found"; exit -1; fi;;
95 -jmxport) shift; jmxportread="$1"; if [[ "${jmxportread}" =~ ^[0-9]+$ ]] ; then jmxport=${jmxportread}; shift; else echo "-jmxport expects a number but was not found"; exit -1; fi;;
96 -start) startdaemon=1; shift; daemonportread="$1"; if [[ "${daemonportread}" =~ ^[0-9]+$ ]] ; then daemonport=${daemonportread}; shift; fi;;
97 -stop) stopdaemon=1; shift ;;
98 -status) statusdaemon=1; shift ;;
100 -help) dohelp=1; shift;;
101 -Xmx*) jvmMaxMemory="$1"; shift;;
102 -D*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
103 -X*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
104 -agentpath:*) agentPath="$1"; shift;;
106 *) echo "Unknown option $1"; unknown_option=1; shift ;;
110 # Unknown Options and help
111 if [ "${unknown_option}" -eq 1 ]; then
115 if [ "${dohelp}" -eq 1 ]; then
119 if [ "${jvmMaxMemory}" == "" ]; then
120 jvmMaxMemory="-Xmx1G"
121 echo "*****************************************************************"
122 echo "JVM maximum memory was not defined. Setting maximum memory to 1G."
123 echo "To define the maximum memory, specify the -Xmx setting on the"
124 echo "command line. "
125 echo " e.g. ./run.sh -Xmx1G"
126 echo "*****************************************************************"
129 extraJVMOpts="${extraJVMOpts} ${jvmMaxMemory}"
131 # Validate debug port
132 if [[ "${debugport}" -lt 1024 ]] || [[ "${debugport}" -gt 65535 ]]; then
133 echo "Debug Port not in the range [1024,65535] ${debugport}"
137 # Validate daemon console port
138 if [[ "${daemonport}" -lt 1024 ]] || [[ "${daemonport}" -gt 65535 ]]; then
139 echo "Daemon console Port not in the range [1024,65535] value is ${daemonport}"
144 if [[ "${jmxport}" -lt 1024 ]] || [[ "${jmxport}" -gt 65535 ]]; then
145 echo "JMX Port not in the range [1024,65535] value is ${jmxport}"
150 if [ "${debugsuspend}" -eq 1 ]; then
151 extraJVMOpts="${extraJVMOpts} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debugport}"
152 elif [ "${debug}" -eq 1 ]; then
153 extraJVMOpts="${extraJVMOpts} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debugport}"
157 if [ "${startjmx}" -eq 1 ]; then
158 extraJVMOpts="${extraJVMOpts} -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=${jmxport} -Dcom.sun.management.jmxremote"
161 ########################################
162 # Now add to classpath the OSGi JAR
163 ########################################
164 CLASSPATH="${basedir}"/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar
165 FWCLASSPATH=file:"${basedir}"/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar
167 ########################################
168 # Now add the extensions
169 ########################################
171 # Extension 1: this is used to be able to convert all the
172 # bundleresouce: URL in file: so packages that are not OSGi ready can
173 # still work. Notably this is the case for spring classes
174 CLASSPATH=${CLASSPATH}:${basedir}/lib/org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar
175 FWCLASSPATH=${FWCLASSPATH},file:${basedir}/lib/org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar
177 ########################################
178 # Now add the launcher
179 ########################################
180 CLASSPATH=${CLASSPATH}:${basedir}/lib/org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar
181 FWCLASSPATH=${FWCLASSPATH},file:${basedir}/lib/org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar
185 if [ "${stopdaemon}" -eq 1 ]; then
186 if [ -e "${pidfile}" ]; then
187 daemonpid=`cat "${pidfile}"`
190 echo "Controller with PID: ${daemonpid} -- Stopped!"
193 echo "Doesn't seem any Controller daemon is currently running"
198 if [ "${statusdaemon}" -eq 1 ]; then
199 if [ -e "${pidfile}" ]; then
200 daemonpid=`cat "${pidfile}"`
201 ps -p ${daemonpid} > /dev/null
203 if [ "${daemonexists}" -eq 0 ]; then
204 echo "Controller with PID: ${daemonpid} -- Running!"
207 echo "Controller with PID: ${daemonpid} -- Doesn't seem to exist"
212 echo "Doesn't seem any Controller daemon is currently running, at least no PID file has been found"
217 iotmpdir=`echo "${datadir}" | sed 's/ /\\ /g'`
218 bdir=`echo "${basedir}" | sed 's/ /\\ /g'`
219 confarea=`echo "${datadir}" | sed 's/ /\\ /g'`
220 fwclasspath=`echo "${FWCLASSPATH}" | sed 's/ /\\ /g'`
222 if [ "${startdaemon}" -eq 1 ]; then
223 if [ -e "${pidfile}" ]; then
224 echo "Another instance of controller running, check with $0 -status"
227 $JAVA_HOME/bin/java ${extraJVMOpts} \
229 -Djava.io.tmpdir="${iotmpdir}/work/tmp" \
230 -Dosgi.install.area="${bdir}" \
231 -Dosgi.configuration.area="${confarea}/configuration" \
232 -Dosgi.frameworkClassPath="${fwclasspath}" \
233 -Dosgi.framework=file:"${bdir}/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar" \
234 -Djava.awt.headless=true \
235 -classpath "${CLASSPATH}" \
236 org.eclipse.equinox.launcher.Main \
237 -console ${daemonport} \
240 echo ${daemonpid} > ${pidfile}
241 elif [ "${consolestart}" -eq 1 ]; then
242 if [ -e "${pidfile}" ]; then
243 echo "Another instance of controller running, check with $0 -status"
246 $JAVA_HOME/bin/java ${extraJVMOpts} \
248 -Djava.io.tmpdir="${iotmpdir}/work/tmp" \
249 -Dosgi.install.area="${bdir}" \
250 -Dosgi.configuration.area="${confarea}/configuration" \
251 -Dosgi.frameworkClassPath="${fwclasspath}" \
252 -Dosgi.framework=file:"${bdir}/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar" \
253 -Djava.awt.headless=true \
254 -classpath "${CLASSPATH}" \
255 org.eclipse.equinox.launcher.Main \