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 -agentpath:*) agentPath="$1"; shift;;
117 *) echo "Unknown option $1"; unknown_option=1; break ;;
123 if [ "${unknown_option}" -eq 1 ]; then
124 echo "Use -help for more information."
129 if [ "${dohelp}" -eq 1 ]; then
130 . ${basedir}/functions.sh
131 harvestHelp ${helper}
132 echo -e '\nFor other information type -help.\n'
136 extraJVMOpts="${extraJVMOpts} ${jvmMaxMemory}"
139 #debugport [-debugport <num>] - DEFAULT is 8000
141 # Set address for settings in runjdwp in extra JVM options.
142 # The address is transport address for the connection.
143 # The address has to be in the range [1024,65535]. If this option was not call, port will be set to default value.
145 # Validate debug port
146 if [[ "${debugport}" -lt 1024 ]] || [[ "${debugport}" -gt 65535 ]]; then
147 echo "Debug Port not in the range [1024,65535] ${debugport}"
151 # Validate daemon console port
152 if [[ "${daemonport}" -lt 1024 ]] || [[ "${daemonport}" -gt 65535 ]]; then
153 echo "Daemon console Port not in the range [1024,65535] value is ${daemonport}"
158 #jmxport [-jmxport <num>] - DEFAULT is 1088
160 # 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.
163 if [[ "${jmxport}" -lt 1024 ]] || [[ "${jmxport}" -gt 65535 ]]; then
164 echo "JMX Port not in the range [1024,65535] value is ${jmxport}"
170 #Run ODL controller with -Xdebug and -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=\${debugport}
171 #-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.
172 #-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
173 #communicate with a separate debugger application.
174 #settings for -Xrunjdwp:
175 # transport - name of the transport to use in connecting to debugger application
176 # server - if “y”, listen for a debugger application to attach; otherwise, attach to the debugger application at the specified address
177 # - 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
178 # suspend - if “y”, VMStartEvent has a suspend Policy of SUSPEND_ALL
179 # - if “n”, VMStartEvent has a suspend policy of SUSPEND_NONE
180 # address - transport address for the connection
181 # - if server=n, attempt to attach to debugger application at this address
182 # - if server=y, listen for a connection at this address
186 #debugsuspend [-debugsuspend]
188 #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.
191 if [ "${debugsuspend}" -eq 1 ]; then
192 extraJVMOpts="${extraJVMOpts} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debugport}"
193 elif [ "${debug}" -eq 1 ]; then
194 extraJVMOpts="${extraJVMOpts} -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=${debugport}"
199 #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
200 #jmxport can by set with command -jmxport <num>. Default num for the option is 1088.
203 if [ "${startjmx}" -eq 1 ]; then
204 extraJVMOpts="${extraJVMOpts} -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=${jmxport} -Dcom.sun.management.jmxremote"
207 ########################################
208 # Now add to classpath the OSGi JAR
209 ########################################
210 CLASSPATH=${CLASSPATH}:${basedir}/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar
211 FWCLASSPATH=file:"${basedir}"/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar
213 ########################################
214 # Now add the extensions
215 ########################################
217 # Extension 1: this is used to be able to convert all the
218 # bundleresouce: URL in file: so packages that are not OSGi ready can
219 # still work. Notably this is the case for spring classes
220 CLASSPATH=${CLASSPATH}:${basedir}/lib/org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar
221 FWCLASSPATH=${FWCLASSPATH},file:${basedir}/lib/org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar
223 ########################################
224 # Now add the launcher
225 ########################################
226 CLASSPATH=${CLASSPATH}:${basedir}/lib/org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar
227 FWCLASSPATH=${FWCLASSPATH},file:${basedir}/lib/org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar
234 #If a controller is running, the command stop controller. Pid will be clean.
236 if [ "${stopdaemon}" -eq 1 ]; then
237 if [ -e "${pidfile}" ]; then
238 daemonpid=`cat "${pidfile}"`
241 echo "Controller with PID: ${daemonpid} -- Stopped!"
244 echo "Doesn't seem any Controller daemon is currently running"
252 #Find out whether a controller is running and print it.
254 if [ "${statusdaemon}" -eq 1 ]; then
255 if [ -e "${pidfile}" ]; then
256 daemonpid=`cat "${pidfile}"`
257 ps -p ${daemonpid} > /dev/null
259 if [ "${daemonexists}" -eq 0 ]; then
260 echo "Controller with PID: ${daemonpid} -- Running!"
263 echo "Controller with PID: ${daemonpid} -- Doesn't seem to exist"
268 echo "Doesn't seem any Controller daemon is currently running, at least no PID file has been found"
273 iotmpdir=`echo "${datadir}" | sed 's/ /\\ /g'`
274 bdir=`echo "${basedir}" | sed 's/ /\\ /g'`
275 confarea=`echo "${datadir}" | sed 's/ /\\ /g'`
276 fwclasspath=`echo "${FWCLASSPATH}" | sed 's/ /\\ /g'`
279 #start [-start [<console port>]]
281 # 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.
289 #agentpath [-agentpath:<path to lib>]
291 # Agentpath option passes path to agent to jvm in order to load native agent library, e.g. yourkit profiler agent.
293 echo "JVM maximum memory was set to ${jvmMaxMemory}."
294 if [ "${startdaemon}" -eq 1 ]; then
295 if [ -e "${pidfile}" ]; then
296 echo "Another instance of controller running, check with $0 -status"
299 $JAVA_HOME/bin/java ${extraJVMOpts} \
301 -Djava.io.tmpdir="${iotmpdir}/work/tmp" \
302 -Dosgi.install.area="${bdir}" \
303 -Dosgi.configuration.area="${confarea}/configuration" \
304 -Dosgi.frameworkClassPath="${fwclasspath}" \
305 -Dosgi.framework=file:"${bdir}/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar" \
306 -Djava.awt.headless=true \
307 -classpath "${CLASSPATH}" \
308 org.eclipse.equinox.launcher.Main \
309 -console ${daemonport} \
312 echo ${daemonpid} > ${pidfile}
313 elif [ "${consolestart}" -eq 1 ]; then
314 if [ -e "${pidfile}" ]; then
315 echo "Another instance of controller running, check with $0 -status"
318 $JAVA_HOME/bin/java ${extraJVMOpts} \
320 -Djava.io.tmpdir="${iotmpdir}/work/tmp" \
321 -Dosgi.install.area="${bdir}" \
322 -Dosgi.configuration.area="${confarea}/configuration" \
323 -Dosgi.frameworkClassPath="${fwclasspath}" \
324 -Dosgi.framework=file:"${bdir}/lib/org.eclipse.osgi-3.8.1.v20120830-144521.jar" \
325 -Djava.awt.headless=true \
326 -classpath "${CLASSPATH}" \
327 org.eclipse.equinox.launcher.Main \