Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 7d1e9aa72fc4a2c27ecbd4cb30bf3dde7bebbd13 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
@echo off
rem Script for starting and stopping the kernel

if "%OS%" == "Windows_NT" setlocal

rem Derive full path for script (includes trailing backslash)
  set SCRIPT_DIR=%~dp0

if exist "%SCRIPT_DIR%setupVars.bat" (
  call "%SCRIPT_DIR%setupVars.bat"
  if not "%ERRORLEVEL%"=="0" (
    if "%OS%" == "Windows_NT" endlocal
    exit /B %ERRORLEVEL%
  )
) else (
  echo Cannot set up environment. "setupVars.bat" file missing.
  if "%OS%" == "Windows_NT" endlocal
  exit /B 1
)

rem Select command we are to run

  rem First parm is command
    set COMMAND=%~1
    rem Rest are parameters - shift done in subroutines
   
  rem Switch on COMMAND in {"start","stop"}

    if "%COMMAND%" == "start" (
      call :doStartCommand %*
      if "%OS%" == "Windows_NT" endlocal
      exit /B 0
    )

    if "%COMMAND%" == "stop"  (
      call :doStopCommand  %*
      if "%OS%" == "Windows_NT" endlocal
      exit /B 0
    )

    echo Unknown command: %COMMAND%
    if "%OS%" == "Windows_NT" endlocal
    exit /B 1

rem ------------------ Subroutines
rem ------------------------------
:doStartCommand

  shift
  rem The shift must be here :()

  rem Check further file that needs to exist
  for %%I in ("%KERNEL_HOME%\bin\jmxPermissions.vbs") do if not exist "%%~I" (
    echo File "%%~I" does not exist but is required to continue.
    exit /B 1
  )

  rem Set defaults
    set CONFIG_DIR=%KERNEL_HOME%\config
    set CLEAN_FLAG=
    set DEBUG_FLAG=
    set DEBUG_PORT=8000
    set SUSPEND=n
    if not defined JMX_PORT set JMX_PORT=9875
    if not defined KEYSTORE_PASSWORD set KEYSTORE_PASSWORD=changeit
    set ADDITIONAL_ARGS=

  rem Loop through options

  :startOptionLoop
  if "%~1"=="" goto endStartOptionLoop
  if "%~1"=="-debug"             goto debug
  if "%~1"=="-clean"             goto clean
  if "%~1"=="-configDir"         goto configDir
  if "%~1"=="-jmxport"           goto jmxport
  if "%~1"=="-keystore"          goto keystore
  if "%~1"=="-keystorePassword"  goto keystorePassword
  if "%~1"=="-suspend"           goto suspend
  if "%~1"=="-shell"             goto shell

  set ADDITIONAL_ARGS=%ADDITIONAL_ARGS% "%~1"

  :continueStartOptionLoop
    shift
    goto startOptionLoop

  :debug
    set DEBUG_FLAG=1
    set PORT_CANDIDATE=%~2
    if not "%PORT_CANDIDATE:~0,1%"=="-" (
      set DEBUG_PORT=%PORT_CANDIDATE%
      shift
    )
    goto continueStartOptionLoop
  :clean
    set CLEAN_FLAG=1
    goto continueStartOptionLoop
  :configDir
    set CONFIG_DIR=%~2
    rem check it is absolute, relative to the kernel home
	if not "%CONFIG_DIR:~1,2%"==":\" set CONFIG_DIR=%KERNEL_HOME%\%CONFIG_DIR%
	if "%CONFIG_DIR:-1%"=="\" set CONFIG_DIR=%CONFIG_DIR:~-1%
    shift
    goto continueStartOptionLoop
  :jmxport
    set JMX_PORT=%~2
    shift
    goto continueStartOptionLoop
  :keystore
    set KEYSTORE_PATH=%~2
    shift
    goto continueStartOptionLoop
  :keystorePassword
    set KEYSTORE_PASSWORD=%~2
    shift
    goto continueStartOptionLoop
  :suspend
    set SUSPEND=y
    goto continueStartOptionLoop
  :shell
    set SHELL_FLAG=1
    goto continueStartOptionLoop

  :endStartOptionLoop

  
  rem Adjust permissions if necessary
    cscript //NoLogo "%KERNEL_HOME%\bin\jmxPermissions.vbs" "%CONFIG_DIR%\"

  rem Adjust options now all are known
    if "%KEYSTORE_PATH%"=="" set KEYSTORE_PATH=%CONFIG_DIR%\keystore
    if not "%DEBUG_FLAG%"=="" set DEBUG_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=%DEBUG_PORT%,server=y,suspend=%SUSPEND%

  rem do Clean work:
    if not "%CLEAN_FLAG%"=="" (
      rmdir /Q /S "%KERNEL_HOME%\serviceability"
	  rmdir /Q /S "%KERNEL_HOME%\work"
      set LAUNCH_OPTS=%LAUNCH_OPTS% -Fosgi.clean=true
    )

  rem ensure that the tmp directory exists:
  set TMP_DIR="%KERNEL_HOME%\work\tmp"
  if not exist "%TMP_DIR%" mkdir "%TMP_DIR%"

  rem do Shell work:
    if not "%SHELL_FLAG%"=="" (      
      set LAUNCH_OPTS=%LAUNCH_OPTS% -Forg.eclipse.virgo.kernel.shell.local=true
    )

  rem Set JMX options
    set JMX_OPTS=%JMX_OPTS% -Dcom.sun.management.jmxremote.port=%JMX_PORT% 
    set JMX_OPTS=%JMX_OPTS% -Dcom.sun.management.jmxremote.authenticate=true 
    set JMX_OPTS=%JMX_OPTS% -Dcom.sun.management.jmxremote.login.config=virgo-kernel 
    set JMX_OPTS=%JMX_OPTS% -Dcom.sun.management.jmxremote.access.file="%CONFIG_DIR%\org.eclipse.virgo.kernel.jmxremote.access.properties" 
    set JMX_OPTS=%JMX_OPTS% -Djavax.net.ssl.keyStore="%KEYSTORE_PATH%" 
    set JMX_OPTS=%JMX_OPTS% -Djavax.net.ssl.keyStorePassword=%KEYSTORE_PASSWORD% 
    set JMX_OPTS=%JMX_OPTS% -Dcom.sun.management.jmxremote.ssl=true 
    set JMX_OPTS=%JMX_OPTS% -Dcom.sun.management.jmxremote.ssl.need.client.auth=false

  rem Run the server
    
    rem Marshall parameters
    set KERNEL_JAVA_PARMS=%JAVA_OPTS% %DEBUG_OPTS% %JMX_OPTS%

    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -XX:+HeapDumpOnOutOfMemoryError 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -XX:ErrorFile="%KERNEL_HOME%\serviceability\error.log" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -XX:HeapDumpPath="%KERNEL_HOME%\serviceability\heap_dump.hprof"
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -Djava.security.auth.login.config="%CONFIG_DIR%\org.eclipse.virgo.kernel.authentication.config" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -Dorg.eclipse.virgo.kernel.authentication.file="%CONFIG_DIR%\org.eclipse.virgo.kernel.users.properties" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -Djava.io.tmpdir="%TMP_DIR%" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -Dorg.eclipse.virgo.kernel.home="%KERNEL_HOME%" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -classpath "%CLASSPATH%" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% org.eclipse.virgo.osgi.launcher.Launcher 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -config "%KERNEL_HOME%\lib\org.eclipse.virgo.kernel.launch.properties" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -Forg.eclipse.virgo.kernel.home="%KERNEL_HOME%" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -Forg.eclipse.virgo.kernel.config="%CONFIG_DIR%" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -Fosgi.configuration.area="%KERNEL_HOME%\work\osgi\configuration" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% -Fosgi.java.profile="file:%KERNEL_HOME%\lib\java6-server.profile" 
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% %LAUNCH_OPTS%
    set KERNEL_JAVA_PARMS=%KERNEL_JAVA_PARMS% %ADDITIONAL_ARGS%
	
    rem Now run it
	PUSHD %KERNEL_HOME%
    "%JAVA_HOME%\bin\java" %KERNEL_JAVA_PARMS%
    POPD

goto :eof

rem ------------------------------
:doStopCommand
  
  shift
  rem The shift must be here :()

  rem Set defaults
    if not defined TRUSTSTORE_PATH set TRUSTSTORE_PATH=%KERNEL_HOME%\config\keystore
    if not defined TRUSTSTORE_PASSWORD set TRUSTSTORE_PASSWORD=changeit
    set OTHER_ARGS=

  rem Loop through options

  :stopOptionLoop
    if "%~1"=="" goto endStopOptionLoop
  
    if "%~1"=="-truststore" (
      set TRUSTSTORE_PATH=%~2
      shift
    ) else (
      if "%~1"=="-truststorePassword" (
        set TRUSTSTORE_PASSWORD=%~2
        shift
      ) else (
        set OTHER_ARGS=%OTHER_ARGS% "%~1"
      )
    )
    
    shift
    goto stopOptionLoop
  :endStopOptionLoop

  rem Call shutdown client

    rem Extend JMX options
    set JMX_OPTS=%JMX_OPTS% -Djavax.net.ssl.trustStore="%TRUSTSTORE_PATH%"
    set JMX_OPTS=%JMX_OPTS% -Djavax.net.ssl.trustStorePassword=%TRUSTSTORE_PASSWORD%

    rem Marshall parameters
    set SHUTDOWN_PARMS= %JAVA_OPTS% %JMX_OPTS%
    set SHUTDOWN_PARMS=%SHUTDOWN_PARMS% -classpath "%CLASSPATH%"
    set SHUTDOWN_PARMS=%SHUTDOWN_PARMS% -Dorg.eclipse.virgo.kernel.home="%KERNEL_HOME%"
    set SHUTDOWN_PARMS=%SHUTDOWN_PARMS% org.eclipse.virgo.kernel.shutdown.ShutdownClient
    set SHUTDOWN_PARMS=%SHUTDOWN_PARMS% %OTHER_ARGS%

    rem Run Java program
	PUSHD %KERNEL_HOME%
    "%JAVA_HOME%\bin\java" %SHUTDOWN_PARMS%
    POPD

goto :eof

Back to the top