4 # For more information on a specific command, type -help command-name.
7 # jmxport [-jmxport <num>] - DEFAULT is 1088
9 # debugsuspend [-debugsuspend]
10 # debugport [-debugport <num>] - DEFAULT is 8000
11 # start [-start [<console port>]] - DEFAULT port is 2400
15 # agentpath [-agentpath:<path to lib>]
20 if [[ "$unamestr" == 'Linux' ]]; then
22 elif [[ "$unamestr" == 'Darwin' ]]; then
26 if [[ $platform == 'linux' ]]; then
27 fullpath=`readlink -f $0`
29 if [[ -z ${JAVA_HOME} ]]; then
30 # Find the actual location of the Java launcher:
31 java_launcher=`command -v java`
32 java_launcher=`readlink -f "${java_launcher}"`
34 # Compute the Java home from the location of the Java launcher:
35 export JAVA_HOME="${java_launcher%/bin/java}"
37 elif [[ $platform == 'osx' ]]; then
39 cd `dirname "$TARGET_FILE"`
40 TARGET_FILE=`basename $TARGET_FILE`
42 # Iterate down a (possible) chain of symlinks
43 while [ -L "$TARGET_FILE" ]
45 TARGET_FILE=`readlink "$TARGET_FILE"`
46 cd `dirname "$TARGET_FILE"`
47 TARGET_FILE=`basename "$TARGET_FILE"`
50 # Compute the canonicalized name by finding the physical path
51 # for the directory we're in and appending the target file.
53 RESULT=$PHYS_DIR/$TARGET_FILE
56 [[ -z ${JAVA_HOME} ]] && [[ -x "/usr/libexec/java_home" ]] && export JAVA_HOME=`/usr/libexec/java_home -v 1.7`;
60 [[ -z ${JAVA_HOME} ]] && echo "Need to set JAVA_HOME environment variable" && exit -1;
61 [[ ! -x ${JAVA_HOME}/bin/java ]] && echo "Cannot find an executable \
62 JVM at path ${JAVA_HOME}/bin/java check your JAVA_HOME" && exit -1;
64 if [ -z ${ODL_BASEDIR} ]; then
65 basedir=`dirname "${fullpath}"`
67 basedir=${ODL_BASEDIR}
70 if [ -z ${ODL_DATADIR} ]; then
71 datadir=`dirname "${fullpath}"`
73 datadir=${ODL_DATADIR}
76 if [ -z ${TMP} ]; then
77 pidfile="/tmp/opendaylight.PID"
79 pidfile="${TMP}/opendaylight.PID"
102 -debug) debug=1; shift ;;
103 -help) dohelp=1; shift; helper=$1; break ;;
104 -jmx) startjmx=1; shift ;;
105 -debugsuspend) debugsuspend=1; shift ;;
106 -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;;
107 -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;;
108 -start) startdaemon=1; shift; daemonportread="$1"; if [[ "${daemonportread}" =~ ^[0-9]+$ ]] ; then daemonport=${daemonportread}; shift; fi;;
109 -stop) stopdaemon=1; shift ;;
110 -status) statusdaemon=1; shift ;;
112 -Xmx*) jvmMaxMemory="$1"; shift;;
113 -D*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
114 -X*) extraJVMOpts="${extraJVMOpts} $1"; shift;;
115 -J*) extraJVMOpts="${extraJVMOpts} -$(echo "$1" | cut -d'J' -f2)"; shift;;
116 -agentpath:*) agentPath="$1"; shift;;
118 *) echo "Unknown option $1"; unknown_option=1; break ;;
124 if [ "${unknown_option}" -eq 1 ]; then
125 echo "Use -help for more information."
130 if [ "${dohelp}" -eq 1 ]; then
131 . ${basedir}/functions.sh
132 harvestHelp ${helper}
133 echo -e '\nFor other information type -help.\n'
137 extraJVMOpts="${extraJVMOpts} ${jvmMaxMemory}"
140 #debugport [-debugport <num>] - DEFAULT is 8000
142 # Set address for settings in runjdwp in extra JVM options.
143 # The address is transport address for the connection.
144 # The address has to be in the range [1024,65535]. If this option was not call, port will be set to default value.
146 # Validate debug port
147 if [[ "${debugport}" -lt 1024 ]] || [[ "${debugport}" -gt 65535 ]]; then
148 echo "Debug Port not in the range [1024,65535] ${debugport}"
152 # Validate daemon console port
153 if [[ "${daemonport}" -lt 1024 ]] || [[ "${daemonport}" -gt 65535 ]]; then
154 echo "Daemon console Port not in the range [1024,65535] value is ${daemonport}"
159 #jmxport [-jmxport <num>] - DEFAULT is 1088
161 # Set jmx port for com.sun.management.jmxremote.port in JMX support. Port has to be in the range [1024,65535]. If this option was not call, port will be set to default value.
164 if [[ "${jmxport}" -lt 1024 ]] || [[ "${jmxport}" -gt 65535 ]]; then
165 echo "JMX Port not in the range [1024,65535] value is ${jmxport}"
171 #Run ODL controller with -Xdebug and -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=\${debugport}
172 #-Xdebug enables debugging capabilities in the JVM which are used by the Java Virtual Machine Tools Interface (JVMTI). JVMTI is a low-level debugging interface used by debuggers and profiling tools.
173 #-Xrunjdwp option loads the JPDA reference implementation of JDWP. This library resides in the target VM and uses JVMDI and JNI to interact with it. It uses a transport and the JDWP protocol to
174 #communicate with a separate debugger application.
175 #settings for -Xrunjdwp:
176 # transport - name of the transport to use in connecting to debugger application
177 # server - if “y”, listen for a debugger application to attach; otherwise, attach to the debugger application at the specified address
178 # - if “y” and no address is specified, choose a transport address at which to listen for a debugger application, and print the address to the standard output stream
179 # suspend - if “y”, VMStartEvent has a suspend Policy of SUSPEND_ALL
180 # - if “n”, VMStartEvent has a suspend policy of SUSPEND_NONE
181 # address - transport address for the connection
182 # - if server=n, attempt to attach to debugger application at this address
183 # - if server=y, listen for a connection at this address
187 #debugsuspend [-debugsuspend]
189 #This command sets suspend on true in runjdwp in extra JVM options. If its true, VMStartEvent has a suspendPolicy of SUSPEND_ALL. If its false, VMStartEvent has a suspendPolicy of SUSPEND_NONE.
192 if [ "${debugsuspend}" -eq 1 ]; then
193 extraJVMOpts="${extraJVMOpts} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debugport}"
194 elif [ "${debug}" -eq 1 ]; then
195 extraJVMOpts="${extraJVMOpts} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debugport}"
200 #Add JMX support. With settings for extra JVM options: -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=\${jmxport} -Dcom.sun.management.jmxremote
201 #jmxport can by set with command -jmxport <num>. Default num for the option is 1088.
204 if [ "${startjmx}" -eq 1 ]; then
205 extraJVMOpts="${extraJVMOpts} -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=${jmxport} -Dcom.sun.management.jmxremote"
208 ########################################
209 # Now add to classpath the OSGi JAR
210 ########################################
211 CLASSPATH=${CLASSPATH}:${basedir}/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar
212 FWCLASSPATH=file:"${basedir}"/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar
214 ########################################
215 # Now add the extensions
216 ########################################
218 # Extension 1: this is used to be able to convert all the
219 # bundleresouce: URL in file: so packages that are not OSGi ready can
220 # still work. Notably this is the case for spring classes
221 CLASSPATH=${CLASSPATH}:${basedir}/lib/org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar
222 FWCLASSPATH=${FWCLASSPATH},file:${basedir}/lib/org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar
224 ########################################
225 # Now add the launcher
226 ########################################
227 CLASSPATH=${CLASSPATH}:${basedir}/lib/org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar
228 FWCLASSPATH=${FWCLASSPATH},file:${basedir}/lib/org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar
235 #If a controller is running, the command stop controller. Pid will be clean.
237 if [ "${stopdaemon}" -eq 1 ]; then
238 if [ -e "${pidfile}" ]; then
239 daemonpid=`cat "${pidfile}"`
242 echo "Controller with PID: ${daemonpid} -- Stopped!"
245 echo "Doesn't seem any Controller daemon is currently running"
253 #Find out whether a controller is running and print it.
255 if [ "${statusdaemon}" -eq 1 ]; then
256 if [ -e "${pidfile}" ]; then
257 daemonpid=`cat "${pidfile}"`
258 ps -p ${daemonpid} > /dev/null
260 if [ "${daemonexists}" -eq 0 ]; then
261 echo "Controller with PID: ${daemonpid} -- Running!"
264 echo "Controller with PID: ${daemonpid} -- Doesn't seem to exist"
269 echo "Doesn't seem any Controller daemon is currently running, at least no PID file has been found"
274 iotmpdir=`echo "${datadir}" | sed 's/ /\\ /g'`
275 bdir=`echo "${basedir}" | sed 's/ /\\ /g'`
276 confarea=`echo "${datadir}" | sed 's/ /\\ /g'`
277 fwclasspath=`echo "${FWCLASSPATH}" | sed 's/ /\\ /g'`
280 #start [-start [<console port>]]
282 # If controller is not running, the command with argument(for set port, where controller has start) will start new controller on a port. The port has to be in the range [1024,65535]. If this option was not call, port will be set to default value. Pid will be create.
290 #agentpath [-agentpath:<path to lib>]
292 # Agentpath option passes path to agent to jvm in order to load native agent library, e.g. yourkit profiler agent.
294 echo "JVM maximum memory was set to ${jvmMaxMemory}."
295 if [ "${startdaemon}" -eq 1 ]; then
296 if [ -e "${pidfile}" ]; then
297 echo "Another instance of controller running, check with $0 -status"
300 $JAVA_HOME/bin/java ${extraJVMOpts} \
302 -Djava.io.tmpdir="${iotmpdir}/work/tmp" \
303 -Dosgi.install.area="${bdir}" \
304 -Dosgi.configuration.area="${confarea}/configuration" \
305 -Dosgi.frameworkClassPath="${fwclasspath}" \
306 -Dosgi.framework=file:"${bdir}/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar" \
307 -Djava.awt.headless=true \
308 -classpath "${CLASSPATH}" \
309 org.eclipse.equinox.launcher.Main \
310 -console ${daemonport} \
313 echo ${daemonpid} > ${pidfile}
314 elif [ "${consolestart}" -eq 1 ]; then
315 if [ -e "${pidfile}" ]; then
316 echo "Another instance of controller running, check with $0 -status"
319 $JAVA_HOME/bin/java ${extraJVMOpts} \
321 -Djava.io.tmpdir="${iotmpdir}/work/tmp" \
322 -Dosgi.install.area="${bdir}" \
323 -Dosgi.configuration.area="${confarea}/configuration" \
324 -Dosgi.frameworkClassPath="${fwclasspath}" \
325 -Dosgi.framework=file:"${bdir}/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar" \
326 -Djava.awt.headless=true \
327 -classpath "${CLASSPATH}" \
328 org.eclipse.equinox.launcher.Main \