/
standalone.sh
401 lines (365 loc) · 12.6 KB
/
standalone.sh
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!/bin/sh
# Use --debug to activate debug mode with an optional argument to specify the port.
# Usage : standalone.sh --debug
# standalone.sh --debug 9797
# By default debug mode is disabled.
# Identifies the launch script type.
export JBOSS_LAUNCH_SCRIPT="linux"
DEBUG_MODE="${DEBUG:-false}"
DEBUG_PORT="${DEBUG_PORT:-8787}"
GC_LOG="$GC_LOG"
SERVER_OPTS=""
while [ "$#" -gt 0 ]
do
case "$1" in
--debug)
DEBUG_MODE=true
if [ -n "$2" ] && [ "$2" = `echo "$2" | sed 's/-//'` ]; then
DEBUG_PORT=$2
shift
fi
;;
-Djava.security.manager*)
echo "ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable."
exit 1
;;
-secmgr)
SECMGR="true"
;;
--)
shift
break;;
*)
SERVER_OPTS="$SERVER_OPTS \"$1\""
;;
esac
shift
done
DIRNAME=`dirname "$0"`
PROGNAME=`basename "$0"`
GREP="grep"
. "$DIRNAME/common.sh"
# Use the maximum available, or set MAX_FD != -1 to use that
MAX_FD="maximum"
# tell linux glibc how many memory pools can be created that are used by malloc
MALLOC_ARENA_MAX="${MALLOC_ARENA_MAX:-1}"
export MALLOC_ARENA_MAX
# OS specific support (must be 'true' or 'false').
cygwin=false;
darwin=false;
linux=false;
solaris=false;
freebsd=false;
other=false
case "`uname`" in
CYGWIN*)
cygwin=true
;;
Darwin*)
darwin=true
;;
FreeBSD)
freebsd=true
;;
Linux)
linux=true
;;
SunOS*)
solaris=true
;;
*)
other=true
;;
esac
# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin ; then
[ -n "$JBOSS_HOME" ] &&
JBOSS_HOME=`cygpath --unix "$JBOSS_HOME"`
[ -n "$JAVA_HOME" ] &&
JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
[ -n "$JAVAC_JAR" ] &&
JAVAC_JAR=`cygpath --unix "$JAVAC_JAR"`
fi
# Setup JBOSS_HOME
RESOLVED_JBOSS_HOME=`cd "$DIRNAME/.." >/dev/null; pwd`
if [ "x$JBOSS_HOME" = "x" ]; then
# get the full path (without any relative bits)
JBOSS_HOME=$RESOLVED_JBOSS_HOME
else
SANITIZED_JBOSS_HOME=`cd "$JBOSS_HOME"; pwd`
if [ "$RESOLVED_JBOSS_HOME" != "$SANITIZED_JBOSS_HOME" ]; then
echo ""
echo " WARNING: JBOSS_HOME may be pointing to a different installation - unpredictable results may occur."
echo ""
echo " JBOSS_HOME: $JBOSS_HOME"
echo ""
sleep 2s
fi
fi
export JBOSS_HOME
# Read an optional running configuration file
if [ "x$RUN_CONF" = "x" ]; then
RUN_CONF="$DIRNAME/standalone.conf"
fi
if [ -r "$RUN_CONF" ]; then
. "$RUN_CONF"
fi
# Set debug settings if not already set
if [ "$DEBUG_MODE" = "true" ]; then
DEBUG_OPT=`echo $JAVA_OPTS | $GREP "\-agentlib:jdwp"`
if [ "x$DEBUG_OPT" = "x" ]; then
JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,address=$DEBUG_PORT,server=y,suspend=n"
else
echo "Debug already enabled in JAVA_OPTS, ignoring --debug argument"
fi
fi
# Setup the JVM
if [ "x$JAVA" = "x" ]; then
if [ "x$JAVA_HOME" != "x" ]; then
JAVA="$JAVA_HOME/bin/java"
else
JAVA="java"
fi
fi
if $linux; then
# consolidate the server and command line opts
CONSOLIDATED_OPTS="$JAVA_OPTS $SERVER_OPTS"
# process the standalone options
for var in $CONSOLIDATED_OPTS
do
# Remove quotes
p=`echo $var | tr -d "'" | tr -d "\""`
case $p in
-Djboss.server.base.dir=*)
JBOSS_BASE_DIR=`readlink -m ${p#*=}`
;;
-Djboss.server.log.dir=*)
JBOSS_LOG_DIR=`readlink -m ${p#*=}`
;;
-Djboss.server.config.dir=*)
JBOSS_CONFIG_DIR=`readlink -m ${p#*=}`
;;
esac
done
fi
if $solaris; then
# consolidate the server and command line opts
CONSOLIDATED_OPTS="$JAVA_OPTS $SERVER_OPTS"
# process the standalone options
for var in $CONSOLIDATED_OPTS
do
# Remove quotes
p=`echo $var | tr -d "'" | tr -d "\""`
case $p in
-Djboss.server.base.dir=*)
JBOSS_BASE_DIR=`echo $p | awk -F= '{print $2}'`
;;
-Djboss.server.log.dir=*)
JBOSS_LOG_DIR=`echo $p | awk -F= '{print $2}'`
;;
-Djboss.server.config.dir=*)
JBOSS_CONFIG_DIR=`echo $p | awk -F= '{print $2}'`
;;
esac
done
fi
# No readlink -m on BSD
if $darwin || $freebsd || $other ; then
# consolidate the server and command line opts
CONSOLIDATED_OPTS="$JAVA_OPTS $SERVER_OPTS"
# process the standalone options
for var in $CONSOLIDATED_OPTS
do
# Remove quotes
p=`echo $var | tr -d "'" | tr -d "\""`
case $p in
-Djboss.server.base.dir=*)
JBOSS_BASE_DIR=`cd ${p#*=} ; pwd -P`
;;
-Djboss.server.log.dir=*)
if [ -d "${p#*=}" ]; then
JBOSS_LOG_DIR=`cd ${p#*=} ; pwd -P`
else
#since the specified directory doesn't exist we don't validate it
JBOSS_LOG_DIR=${p#*=}
fi
;;
-Djboss.server.config.dir=*)
JBOSS_CONFIG_DIR=`cd ${p#*=} ; pwd -P`
;;
esac
done
fi
# clean server opts
for var in $SERVER_OPTS
do
if [ "${var#"-Djboss.server.base.dir"}" != "$var" ]; then
SERVER_OPTS=${SERVER_OPTS#"$var"}
fi
done
# determine the default base dir, if not set
if [ "x$JBOSS_BASE_DIR" = "x" ]; then
JBOSS_BASE_DIR="$JBOSS_HOME/standalone"
fi
# determine the default log dir, if not set
if [ "x$JBOSS_LOG_DIR" = "x" ]; then
JBOSS_LOG_DIR="$JBOSS_BASE_DIR/log"
fi
# determine the default configuration dir, if not set
if [ "x$JBOSS_CONFIG_DIR" = "x" ]; then
JBOSS_CONFIG_DIR="$JBOSS_BASE_DIR/configuration"
fi
if [ "x$JBOSS_MODULEPATH" = "x" ]; then
JBOSS_MODULEPATH="$JBOSS_HOME/modules"
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
JBOSS_HOME=`cygpath --path --windows "$JBOSS_HOME"`
JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
JBOSS_MODULEPATH=`cygpath --path --windows "$JBOSS_MODULEPATH"`
JBOSS_BASE_DIR=`cygpath --path --windows "$JBOSS_BASE_DIR"`
JBOSS_LOG_DIR=`cygpath --path --windows "$JBOSS_LOG_DIR"`
JBOSS_CONFIG_DIR=`cygpath --path --windows "$JBOSS_CONFIG_DIR"`
fi
if [ "$PRESERVE_JAVA_OPTS" != "true" ]; then
# Set flag if JVM is modular
setModularJdk
if [ "$GC_LOG" = "true" ]; then
# Enable rotating GC logs if the JVM supports it and GC logs are not already enabled
mkdir -p $JBOSS_LOG_DIR
NO_GC_LOG_ROTATE=`echo $JAVA_OPTS | $GREP "\-Xlog\:\?gc"`
if [ "x$NO_GC_LOG_ROTATE" = "x" ]; then
# backup prior gc logs
mv -f "$JBOSS_LOG_DIR/gc.log" "$JBOSS_LOG_DIR/backupgc.log" >/dev/null 2>&1
mv -f "$JBOSS_LOG_DIR/gc.log.0" "$JBOSS_LOG_DIR/backupgc.log.0" >/dev/null 2>&1
mv -f "$JBOSS_LOG_DIR/gc.log.1" "$JBOSS_LOG_DIR/backupgc.log.1" >/dev/null 2>&1
mv -f "$JBOSS_LOG_DIR/gc.log.2" "$JBOSS_LOG_DIR/backupgc.log.2" >/dev/null 2>&1
mv -f "$JBOSS_LOG_DIR/gc.log.3" "$JBOSS_LOG_DIR/backupgc.log.3" >/dev/null 2>&1
mv -f "$JBOSS_LOG_DIR/gc.log.4" "$JBOSS_LOG_DIR/backupgc.log.4" >/dev/null 2>&1
mv -f "$JBOSS_LOG_DIR"/gc.log.*.current "$JBOSS_LOG_DIR/backupgc.log.current" >/dev/null 2>&1
"$JAVA" -Xverbosegclog:"$JBOSS_LOG_DIR/gc.log" -version > /dev/null 2>&1 && OPEN_J9_JDK=true || OPEN_J9_JDK=false
if [ "$OPEN_J9_JDK" = "true" ]; then
TMP_PARAM="-Xverbosegclog:\"$JBOSS_LOG_DIR/gc.log\""
elif [ "$MODULAR_JDK" = "true" ]; then
TMP_PARAM="-Xlog:gc*:file=\"$JBOSS_LOG_DIR/gc.log\":time,uptimemillis:filecount=5,filesize=3M"
else
TMP_PARAM="-verbose:gc -Xloggc:\"$JBOSS_LOG_DIR/gc.log\" -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=3M -XX:-TraceClassUnloading"
fi
eval "$JAVA" $TMP_PARAM -version >/dev/null 2>&1 && PREPEND_JAVA_OPTS="$PREPEND_JAVA_OPTS $TMP_PARAM"
# Remove the gc.log file from the -version check
rm -f "$JBOSS_LOG_DIR/gc.log" >/dev/null 2>&1
fi
fi
JDK_FILTER_SET=`echo $JAVA_OPTS | $GREP "\-Djdk.serialFilter"`
if [ "x$DISABLE_JDK_SERIAL_FILTER" = "x" -a "x$JDK_FILTER_SET" = "x" ]; then
PREPEND_JAVA_OPTS="$PREPEND_JAVA_OPTS -Djdk.serialFilter=\"$JDK_SERIAL_FILTER\""
fi
# Set default modular JVM options
setDefaultModularJvmOptions $JAVA_OPTS
JAVA_OPTS="$JAVA_OPTS $DEFAULT_MODULAR_JVM_OPTIONS"
# Set default Security Manager configuration value
setSecurityManagerDefault
JAVA_OPTS="$JAVA_OPTS $SECURITY_MANAGER_CONFIG_OPTION"
JAVA_OPTS="$PREPEND_JAVA_OPTS $JAVA_OPTS"
fi
# Process the JAVA_OPTS and fail the script of a java.security.manager was found
SECURITY_MANAGER_SET=`echo $JAVA_OPTS | $GREP "java\.security\.manager"`
if [ "x$SECURITY_MANAGER_SET" != "x" ]; then
SECURITY_MANAGER_SET_TO_ALLOW=`echo $JAVA_OPTS | $GREP "java\.security\.manager=allow"`
if [ "x$SECURITY_MANAGER_SET_TO_ALLOW" = "x" ]; then
echo "ERROR: The use of -Djava.security.manager has been removed. Please use the -secmgr command line argument or SECMGR=true environment variable."
exit 1
fi
fi
# Set up the module arguments
MODULE_OPTS="$MODULE_OPTS"
if [ "$SECMGR" = "true" ]; then
MODULE_OPTS="$MODULE_OPTS -secmgr";
fi
AGENT_SET=$(echo "$MODULE_OPTS" | $GREP "\-javaagent:")
if [ "x$AGENT_SET" != "x" ]; then
JAVA_OPTS="-javaagent:\"${JBOSS_HOME}/jboss-modules.jar\" ${JAVA_OPTS}"
fi
# Display our environment
echo "========================================================================="
echo ""
echo " JBoss Bootstrap Environment"
echo ""
echo " JBOSS_HOME: $JBOSS_HOME"
echo ""
echo " JAVA: $JAVA"
echo ""
echo " JAVA_OPTS: $JAVA_OPTS"
echo ""
echo "========================================================================="
echo ""
while true; do
if [ "x$LAUNCH_JBOSS_IN_BACKGROUND" = "x" ]; then
# Execute the JVM in the foreground
eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \
\"-Dorg.jboss.boot.log.file="$JBOSS_LOG_DIR"/server.log\" \
\"-Dlogging.configuration=file:"$JBOSS_CONFIG_DIR"/logging.properties\" \
-jar \""$JBOSS_HOME"/jboss-modules.jar\" \
$MODULE_OPTS \
-mp \""${JBOSS_MODULEPATH}"\" \
org.jboss.as.standalone \
-Djboss.home.dir=\""$JBOSS_HOME"\" \
-Djboss.server.base.dir=\""$JBOSS_BASE_DIR"\" \
"$SERVER_OPTS"
JBOSS_STATUS=$?
else
# Execute the JVM in the background
eval \"$JAVA\" -D\"[Standalone]\" $JAVA_OPTS \
\"-Dorg.jboss.boot.log.file="$JBOSS_LOG_DIR"/server.log\" \
\"-Dlogging.configuration=file:"$JBOSS_CONFIG_DIR"/logging.properties\" \
-jar \""$JBOSS_HOME"/jboss-modules.jar\" \
$MODULE_OPTS \
-mp \""${JBOSS_MODULEPATH}"\" \
org.jboss.as.standalone \
-Djboss.home.dir=\""$JBOSS_HOME"\" \
-Djboss.server.base.dir=\""$JBOSS_BASE_DIR"\" \
"$SERVER_OPTS" "&"
JBOSS_PID=$!
# Trap common signals and relay them to the jboss process
trap "kill -HUP $JBOSS_PID" HUP
trap "kill -TERM $JBOSS_PID" INT
trap "kill -QUIT $JBOSS_PID" QUIT
trap "kill -PIPE $JBOSS_PID" PIPE
trap "kill -TERM $JBOSS_PID" TERM
if [ "x$JBOSS_PIDFILE" != "x" ]; then
echo $JBOSS_PID > $JBOSS_PIDFILE
fi
# Wait until the background process exits
WAIT_STATUS=128
while [ "$WAIT_STATUS" -ge 128 ]; do
wait $JBOSS_PID 2>/dev/null
WAIT_STATUS=$?
if [ "$WAIT_STATUS" -gt 128 ]; then
SIGNAL=`expr $WAIT_STATUS - 128`
SIGNAL_NAME=`kill -l $SIGNAL`
echo "*** JBossAS process ($JBOSS_PID) received $SIGNAL_NAME signal ***" >&2
fi
done
if [ "$WAIT_STATUS" -lt 127 ]; then
JBOSS_STATUS=$WAIT_STATUS
else
JBOSS_STATUS=0
fi
if [ "$JBOSS_STATUS" -ne 10 ]; then
# Wait for a complete shutdown
wait $JBOSS_PID 2>/dev/null
fi
if [ "x$JBOSS_PIDFILE" != "x" ]; then
grep "$JBOSS_PID" $JBOSS_PIDFILE && rm $JBOSS_PIDFILE
fi
fi
if [ "$JBOSS_STATUS" -eq 10 ]; then
echo "INFO: Restarting..."
elif [ "$JBOSS_STATUS" -eq 20 ]; then
echo "INFO: Executing the installation manager"
"${JBOSS_HOME}/bin/installation-manager.sh" "${JBOSS_HOME}" "${JBOSS_CONFIG_DIR}/logging.properties"
echo "INFO: Restarting..."
else
exit $JBOSS_STATUS
fi
done