Kill Dynamic Actors when we're done with them
[controller.git] / opendaylight / distribution / opendaylight / src / main / resources / run.bat
1 @ECHO OFF
2 SETLOCAL ENABLEDELAYEDEXPANSION
3
4 IF NOT EXIST "%JAVA_HOME%" (
5     ECHO JAVA_HOME environment variable is not set
6     EXIT /B 2
7 )
8
9 SET basedir=%~dp0
10 SET debugport=8000
11 SET consoleport=2400
12 SET jmxport=1088
13 SET jvmMaxMemory=
14 SET extraJVMOpts=
15 SET consoleOpts=-console -consoleLog
16 SET PID=
17
18 :LOOP
19 IF "%~1" NEQ "" (
20     SET CARG=%~1
21     IF "!CARG!"=="-debug" (
22        SET debugEnabled=true
23        SHIFT
24        GOTO :LOOP
25     )
26     IF "!CARG!"=="-debugsuspend" (
27        SET debugEnabled=true
28        SET debugSuspended=true
29        SHIFT
30        GOTO :LOOP
31     )
32     IF "!CARG!"=="-debugport" (
33        SET debugEnabled=true
34        SET debugport=%~2
35        SHIFT & SHIFT
36        GOTO :LOOP
37     )
38     IF "!CARG!"=="-jmx" (
39        SET jmxEnabled=true
40        SHIFT
41        GOTO :LOOP
42     )
43     IF "!CARG!"=="-jmxport" (
44        SET jmxEnabled=true
45        SET jmxport=%~2
46        SHIFT & SHIFT
47        GOTO :LOOP
48     )
49     IF "!CARG!"=="-start" (
50        SET startEnabled=true
51        SHIFT
52        GOTO :LOOP
53     )
54     IF "!CARG!"=="-consoleport" (
55        SET consoleport=%~2
56        SHIFT & SHIFT
57        GOTO :LOOP
58     )
59     IF "!CARG!"=="-console" (
60        SHIFT
61        GOTO :LOOP
62     )
63     IF "!CARG!"=="-status" (
64        for /F "TOKENS=1" %%G in ('%JAVA_HOME%\bin\jps.exe -lvV ^| find /I "opendaylight"') do (
65            set PID=%%G
66        )
67        if "!PID!" NEQ "" (
68            ECHO Controller is running with PID !PID!
69        ) else (
70            ECHO Controller is not running.
71        )
72        GOTO :EOF
73     )
74     IF "!CARG!"=="-stop" (
75        for /F "TOKENS=1" %%G in ('%JAVA_HOME%\bin\jps.exe -lvV ^| find /I "opendaylight"') do (
76            set PID=%%G
77        )
78        if "!PID!" NEQ "" (
79            ECHO Stopping controller PID !PID!
80            TASKKILL /F /PID !PID!
81        ) else (
82            ECHO Controller is not running.
83        )
84        GOTO :EOF
85     )
86     IF "!CARG:~0,4!"=="-Xmx" (
87        SET jvmMaxMemory=!CARG!
88        SHIFT
89        GOTO :LOOP
90     )
91     IF "!CARG:~0,2!"=="-D" (
92        SET extraJVMOpts=%extraJVMOpts% !CARG!
93        SHIFT
94        GOTO :LOOP
95     )
96     IF "!CARG:~0,2!"=="-X" (
97        SET extraJVMOpts=%extraJVMOpts% !CARG!
98        SHIFT
99        GOTO :LOOP
100     )
101     IF "!CARG!"=="-help" (
102         ECHO "Usage: %0 [-jmx] [-jmxport <num>] [-debug] [-debugsuspend] [-debugport <num>] [-start] [-consoleport <num>]] [-stop] [-status] [-console] [-help] [<other args will automatically be used for the JVM>]"
103         ECHO Note: Enclose any JVM or System properties within double quotes.
104         GOTO :EOF
105     )
106
107     ECHO "Unknown option: !CARG!"
108     EXIT /B 1
109 )
110
111 IF "%debugEnabled%" NEQ "" (
112     REM ECHO "DEBUG enabled"
113     SET extraJVMOpts=%extraJVMOpts% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=%debugport%
114 )
115 IF "%debugSuspended%" NEQ "" (
116     REM ECHO "DEBUG enabled suspended"
117     SET extraJVMOpts=%extraJVMOpts% -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=%debugport%
118 )
119
120 IF "%jvmMaxMemory%"=="" (
121     SET jvmMaxMemory=-Xmx1G
122     ECHO *****************************************************************
123     ECHO JVM maximum memory was not defined. Setting maximum memory to 1G.
124     ECHO To define the maximum memory, specify the -Xmx setting on the
125     ECHO command line.
126     ECHO                    e.g. run.bat -Xmx1G
127     ECHO *****************************************************************"
128 )
129
130 SET extraJVMOpts=%extraJVMOpts%  %jvmMaxMemory%
131
132 IF "%jmxEnabled%" NEQ "" (
133     REM ECHO "JMX enabled "
134     SET extraJVMOpts=%extraJVMOpts% -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=%jmxport% -Dcom.sun.management.jmxremote
135 )
136 IF "%startEnabled%" NEQ "" (
137     REM ECHO "START enabled "
138     SET consoleOpts=-console %consoleport% -consoleLog
139 )
140
141 REM       Check if controller is already running
142 for /F "TOKENS=1" %%G in ('%JAVA_HOME%\bin\jps.exe -lvV ^| find /I "opendaylight"') do (
143     SET PID=%%G
144 )
145 if "!PID!" NEQ "" (
146    ECHO Controller is already running with PID !PID!
147    EXIT /B 1
148 )
149
150
151 REM       Now set the classpath:
152 SET cp="%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar;%basedir%lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar;%basedir%lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
153
154 REM       Now set framework classpath
155 SET fwcp="file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar,file:\%basedir%lib\org.eclipse.virgo.kernel.equinox.extensions-3.6.0.RELEASE.jar,file:\%basedir%lib\org.eclipse.equinox.launcher-1.3.0.v20120522-1813.jar"
156
157 SET RUN_CMD="%JAVA_HOME%\bin\java.exe" -Dopendaylight.controller %extraJVMOpts% -Djava.io.tmpdir="%basedir%work\tmp" -Djava.awt.headless=true -Dosgi.install.area=%basedir% -Dosgi.configuration.area="%basedir%configuration" -Dosgi.frameworkClassPath=%fwcp% -Dosgi.framework="file:\%basedir%lib\org.eclipse.osgi-3.8.1.v20120830-144521.jar" -classpath %cp% org.eclipse.equinox.launcher.Main %consoleOpts%
158
159 ECHO %RUN_CMD%
160
161 if "%startEnabled%" NEQ "" (
162     START /B cmd /C CALL %RUN_CMD% > %basedir%\logs\controller.out 2>&1
163     ECHO Running controller in the background.
164 ) else (
165     %RUN_CMD%
166     EXIT /B %ERRORLEVEL%
167 )
168
169