This repository has been archived by the owner on Jul 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 83
/
rhq-server.sh
executable file
·604 lines (511 loc) · 21.4 KB
/
rhq-server.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
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
#!/bin/sh
# chkconfig: 2345 92 26
# description: Starts and stops the RHQ Server
#
# processname: java
# =============================================================================
# RHQ Server UNIX Startup Script
#
# This file is used to execute the RHQ Server on a UNIX platform as part of
# the platform's bootup sequence or as a foreground console process.
# Run this script without any command line options for the syntax help.
#
# This script is customized by the settings in rhq-server-env.sh. The options
# set there will be applied to this script. It is not recommended to edit this
# script directly.
#
# NOTE: If this script is to be used as an init.d script, you must set
# RHQ_SERVER_HOME so this script knows where to find the Server installation.
#
# This script calls standalone.sh when starting the underlying JBossAS server.
# =============================================================================
# ----------------------------------------------------------------------
# Dumps a message iff debug mode is enabled
# ----------------------------------------------------------------------
debug_msg ()
{
# if debug variable is set, it is assumed to be on, unless its value is false
if [ -n "$RHQ_SERVER_DEBUG" ] && [ "$RHQ_SERVER_DEBUG" != "false" ]; then
echo $1
fi
}
if [ -f "../rhq-server-env.sh" ]; then
. "../rhq-server-env.sh" $*
else
debug_msg "Failed to find rhq-server-env.sh. Continuing with current environment..."
fi
# ----------------------------------------------------------------------
# Environment variables that can customize the launch of the RHQ Server.
# ----------------------------------------------------------------------
# RHQ_SERVER_HOME=/path/to/server/home
# RHQ_SERVER_DEBUG=true
# RHQ_JAVA_HOME=/path/to/java/installation
# RHQ_JAVA_EXE_FILE_PATH=/path/directly/to/java/executable
# RHQ_SERVER_JAVA_OPTS=VM options
# RHQ_SERVER_ADDITIONAL_JAVA_OPTS=additional VM options
# RHQ_SERVER_CMDLINE_OPTS=standalone.sh options
# RHQ_SERVER_ADDITIONAL_CMDLINE_OPTS=additional standalone.sh options
# RHQ_SERVER_STOP_DELAY=5
# RHQ_SERVER_KILL_AFTER_STOP_DELAY=false
# ----------------------------------------------------------------------
# Environment variables to set in order to enable remote debugging.
# ----------------------------------------------------------------------
#RHQ_SERVER_ADDITIONAL_JAVA_OPTS="-agentlib:jdwp=transport=dt_socket,address=8787,server=y,suspend=n"
# Enable JProfiler
#JPROFILER_HOME="/opt/jprofiler6"
#RHQ_SERVER_ADDITIONAL_JAVA_OPTS="$RHQ_SERVER_ADDITIONAL_JAVA_OPTS -agentlib:jprofilerti=port=8849 -Xbootclasspath/a:$JPROFILER_HOME/bin/agent.jar"
#export PATH="$PATH:$JPROFILER_HOME/bin"
#export LD_LIBRARY_PATH="$JPROFILER_HOME/bin/linux-x64"
# ----------------------------------------------------------------------
# Sets _SERVER_STATUS, _SERVER_RUNNING and _SERVER_PID based on the
# status of the RHQ Server VM start script (standalone.sh).
# Also sets _JVM_STATUS, _JVM_RUNNING and _JVM_PID based on the
# status of the JBossAS Java Virtual Machine.
# ----------------------------------------------------------------------
check_status ()
{
if [ -f "$_SERVER_PIDFILE" ]; then
_SERVER_PID=`cat "$_SERVER_PIDFILE"`
if [ -n "$_SERVER_PID" ] && kill -0 $_SERVER_PID 2>/dev/null ; then
_SERVER_STATUS=`printf "%-30s (pid %-7s) is %s" "RHQ Server" $_SERVER_PID $1`
_SERVER_RUNNING=1
else
_SERVER_STATUS=`printf "%-30s (pid %-7s) is down" "RHQ Server" $_SERVER_PID`
_SERVER_RUNNING=0
fi
else
_SERVER_STATUS=`printf "%-30s (no pid file) is down" "RHQ Server"`
_SERVER_RUNNING=0
fi
if [ -f "$_JVM_PIDFILE" ]; then
_JVM_PID=`cat "$_JVM_PIDFILE"`
if [ -n "$_JVM_PID" ] && kill -0 $_JVM_PID 2>/dev/null ; then
_JVM_STATUS=`printf "%-30s (pid %-7s) is %s" "JBossAS Java VM child process" $_JVM_PID $1`
_JVM_RUNNING=1
else
_JVM_STATUS=`printf "%-30s (pid %-7s) is down" "JBossAS Java VM child process" $_JVM_PID`
_JVM_RUNNING=0
fi
else
_JVM_STATUS=`printf "%-30s (no pid file) is down" "JBossAS Java VM child process"`
_JVM_RUNNING=0
fi
add_colors
}
# ----------------------------------------------------------------------
# Function that colors _SERVER_STATUS and _JVM_STATUS if terminal
# supports colors
# ----------------------------------------------------------------------
# helper functions
red () { sed "/$1/s//`printf "\033[31m$2$1\033[0m"`/"; }
green () { sed "/$1/s//`printf "\033[32m$2$1\033[0m"`/"; }
orange () { sed "/$1/s//`printf "\033[33m$1\033[0m"`/"; }
add_colors () {
# find out if terminal support colors
_COLORS_NUM=`tput colors 2> /dev/null`
if [ $? = 0 ] && [ $_COLORS_NUM -gt 2 ]; then
(sh --version | grep bash) 1> /dev/null 2>&1
_IS_BASH=$?
_UP_SYMBOL=`[ $_IS_BASH = 0 ] && echo ✔`
_DOWN_SYMBOL=`[ $_IS_BASH = 0 ] && echo ✘`
_SERVER_STATUS=`echo "${_SERVER_STATUS}" | green running "${_UP_SYMBOL}"`
_SERVER_STATUS=`echo "${_SERVER_STATUS}" | red down "${_DOWN_SYMBOL}"`
_SERVER_STATUS=`echo "${_SERVER_STATUS}" | orange starting`
_SERVER_STATUS=`echo "${_SERVER_STATUS}" | orange killing...`
_JVM_STATUS=`echo "${_JVM_STATUS}" | green running "${_UP_SYMBOL}"`
_JVM_STATUS=`echo "${_JVM_STATUS}" | red down "${_DOWN_SYMBOL}"`
_JVM_STATUS=`echo "${_JVM_STATUS}" | orange starting`
_JVM_STATUS=`echo "${_JVM_STATUS}" | orange killing...`
fi
}
# ----------------------------------------------------------------------
# Ensures that the PID files no longer exist
# ----------------------------------------------------------------------
remove_pid_files ()
{
if [ -f "$_SERVER_PIDFILE" ]; then
rm -f "$_SERVER_PIDFILE"
fi
if [ -f "$_JVM_PIDFILE" ]; then
rm -f "$_JVM_PIDFILE"
fi
}
# ----------------------------------------------------------------------
# Unset any lingering JBossAS environment variables that were set in
# the user's environment. This might happen if the user has an external
# JBossAS installed and configured but doesn't want RHQ to use it.
# ----------------------------------------------------------------------
unset_jboss_as_env ()
{
unset JBOSS_HOME
unset RUN_CONF
unset JAVAC_JAR
unset JBOSS_CLASSPATH
unset JBOSS_BASE_DIR
unset JBOSS_LOG_DIR
unset JBOSS_CONFIG_DIR
}
# ----------------------------------------------------------------------
# Kill RHQ Server
# ----------------------------------------------------------------------
kill_rhq_server ()
{
echo "Trying to kill the RHQ Server..."
echo "RHQ Server parent process (pid=${_SERVER_PID}) is being killed..."
while [ "$_SERVER_RUNNING" = "1" ]; do
kill -9 $_SERVER_PID
sleep 2
check_status "killing..."
done
echo "Java Virtual Machine child process (pid=${_JVM_PID}) is being killed..."
while [ "$_JVM_RUNNING" = "1" ]; do
kill -9 $_JVM_PID
sleep 2
check_status "killing..."
done
remove_pid_files
echo "RHQ Server has been killed."
}
# ----------------------------------------------------------------------
# Determine what specific platform we are running on.
# Set some platform-specific variables.
# ----------------------------------------------------------------------
case "`uname`" in
CYGWIN*) _CYGWIN=true
;;
Linux*) _LINUX=true
;;
Darwin*) _DARWIN=true
;;
SunOS*) _SOLARIS=true
;;
AIX*) _AIX=true
;;
esac
# ----------------------------------------------------------------------
# Determine the RHQ Server installation directory.
# If RHQ_SERVER_HOME is not defined, we will assume we are running
# directly from the server installation's bin/internal directory.
# ----------------------------------------------------------------------
if [ -z "$RHQ_SERVER_HOME" ]; then
command -v readlink >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo >&2 'WARNING: The readlink command is not available on this platform.'
echo >&2 ' If this script was launched from a symbolic link, errors may occur.'
echo >&2 ' Consider installing readlink on this platform.'
_DOLLARZERO="$0"
else
# only certain platforms support the -e argument for readlink
if [ -n "${_LINUX}${_SOLARIS}${_CYGWIN}" ]; then
_READLINK_ARG="-e"
fi
_DOLLARZERO=`readlink $_READLINK_ARG "$0" 2>/dev/null || echo "$0"`
fi
RHQ_SERVER_HOME=`dirname "$_DOLLARZERO"`/../..
else
if [ ! -d "$RHQ_SERVER_HOME" ]; then
echo "ERROR! RHQ_SERVER_HOME is not pointing to a valid directory"
echo "RHQ_SERVER_HOME: $RHQ_SERVER_HOME"
exit 1
fi
fi
cd "$RHQ_SERVER_HOME"
RHQ_SERVER_HOME=`pwd`
debug_msg "RHQ_SERVER_HOME: $RHQ_SERVER_HOME"
# ----------------------------------------------------------------------
# Determine what JBossAS instance to use.
# If RHQ_SERVER_JBOSS_HOME and JBOSS_HOME are both not defined, we will
# assume we are to run the embedded AS instance from the RHQ
# installation directory - RHQ_SERVER_HOME/jbossas
# ----------------------------------------------------------------------
if [ -z "$RHQ_SERVER_JBOSS_HOME" ]; then
if [ -z "$JBOSS_HOME" ]; then
RHQ_SERVER_JBOSS_HOME="${RHQ_SERVER_HOME}/jbossas"
# Unset any lingering JBossAS environment variables that we don't want.
# These could be in the user's environment for an external AS install.
unset_jboss_as_env
else
if [ ! -d "$JBOSS_HOME" ]; then
echo "ERROR! JBOSS_HOME is not pointing to a valid AS directory"
echo "JBOSS_HOME: $JBOSS_HOME"
exit 1
fi
RHQ_SERVER_JBOSS_HOME="${JBOSS_HOME}"
fi
else
if [ ! -d "$RHQ_SERVER_JBOSS_HOME" ]; then
echo "ERROR! RHQ_SERVER_JBOSS_HOME is not pointing to a valid AS directory"
echo "RHQ_SERVER_JBOSS_HOME: $RHQ_SERVER_JBOSS_HOME"
exit 1
fi
unset_jboss_as_env
fi
cd "$RHQ_SERVER_JBOSS_HOME"
RHQ_SERVER_JBOSS_HOME=`pwd`
debug_msg "RHQ_SERVER_JBOSS_HOME: $RHQ_SERVER_JBOSS_HOME"
if [ ! -f "${RHQ_SERVER_JBOSS_HOME}/jboss-modules.jar" ]; then
echo "ERROR! RHQ_SERVER_JBOSS_HOME is not pointing to a valid RHQ Server"
echo "Missing ${RHQ_SERVER_JBOSS_HOME}/jboss-modules.jar"
exit 1
fi
# ----------------------------------------------------------------------
# if we are on a Mac and JAVA_HOME is not set, then set it to /usr
# as this is the default location.
# ----------------------------------------------------------------------
if [ -z "$JAVA_HOME" ]; then
if [ -n "$_DARWIN" ]; then
debug_msg "Running on Mac OS X, setting JAVA_HOME to /usr"
JAVA_HOME=/usr
fi
fi
# ----------------------------------------------------------------------
# create the logs directory
# ----------------------------------------------------------------------
_LOG_DIR_PATH="${RHQ_SERVER_HOME}/logs"
if [ -n "$_CYGWIN" ]; then
_LOG_DIR_PATH=`cygpath --windows --path "$_LOG_DIR_PATH"`
fi
if [ ! -d "${_LOG_DIR_PATH}" ]; then
mkdir "${_LOG_DIR_PATH}"
fi
# ----------------------------------------------------------------------
# Find the Java executable and verify we have a VM available
# Note that RHQ_SERVER_JAVA_* props are still handled for back compat
# ----------------------------------------------------------------------
if [ -z "$RHQ_JAVA_EXE_FILE_PATH" ]; then
if [ ! -z "$RHQ_SERVER_JAVA_EXE_FILE_PATH" ]; then
RHQ_JAVA_EXE_FILE_PATH="$RHQ_SERVER_JAVA_EXE_FILE_PATH"
fi
fi
if [ -z "$RHQ_JAVA_HOME" ]; then
if [ ! -z "$RHQ_SERVER_JAVA_HOME" ]; then
RHQ_JAVA_HOME="$RHQ_SERVER_JAVA_HOME"
fi
fi
if [ -z "$RHQ_JAVA_EXE_FILE_PATH" ]; then
if [ -z "$RHQ_JAVA_HOME" ]; then
debug_msg "No RHQ JAVA property set, defaulting to JAVA_HOME: $JAVA_HOME"
RHQ_JAVA_HOME="$JAVA_HOME"
fi
debug_msg "RHQ_JAVA_HOME: $RHQ_JAVA_HOME"
RHQ_JAVA_EXE_FILE_PATH="${RHQ_JAVA_HOME}/bin/java"
fi
debug_msg "RHQ_JAVA_EXE_FILE_PATH: $RHQ_JAVA_EXE_FILE_PATH"
if [ ! -f "$RHQ_JAVA_EXE_FILE_PATH" ]; then
echo "There is no JVM available."
echo "Please set RHQ_JAVA_HOME or RHQ_JAVA_EXE_FILE_PATH appropriately."
exit 1
fi
# standalone.sh will use JAVA as the full java command
JAVA="$RHQ_JAVA_EXE_FILE_PATH"
export JAVA
# ----------------------------------------------------------------------
# Prepare the VM command line options to be passed in
# ----------------------------------------------------------------------
if [ -z "$RHQ_SERVER_JAVA_OPTS" ]; then
RHQ_SERVER_JAVA_OPTS="-Xms1024M -Xmx1024M -XX:PermSize=256M -XX:MaxPermSize=256M -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000"
fi
if [ -n "$RHQ_SERVER_DEBUG" ] && [ "$RHQ_SERVER_DEBUG" != "false" ]; then
_JBOSS_DEBUG_LOGGING="-Djboss.boot.server.log.level=DEBUG -Djboss.boot.server.log.console.level=DEBUG"
else
_JBOSS_DEBUG_LOGGING=
fi
# Add the JVM opts that we always want to specify, whether or not the user set RHQ_SERVER_JAVA_OPTS.
# Note that the double equals for the policy file specification IS INTENTIONAL
_HTTP_COMPRESSION="-Dorg.apache.coyote.http11.Http11Protocol.COMPRESSION=on -Dorg.apache.coyote.http11.Http11Protocol.COMPRESSION_MIME_TYPES=text/javascript,text/css,text/html"
RHQ_SERVER_JAVA_OPTS="-Dapp.name=rhq-server ${RHQ_SERVER_JAVA_OPTS} -Drhq.server.home=${RHQ_SERVER_HOME} -Djboss.server.log.dir=${_LOG_DIR_PATH} -Djava.awt.headless=true -Dsun.lang.ClassLoader.allowArraySyntax=true -Djboss.server.default.config=standalone-full.xml -Djboss.modules.system.pkgs=org.jboss.byteman -DXXXjava.security.manager -Djava.security.policy==${RHQ_SERVER_HOME}/bin/internal/rhq-server.security-policy ${_HTTP_COMPRESSION} ${_JBOSS_DEBUG_LOGGING}"
debug_msg "RHQ_SERVER_JAVA_OPTS: $RHQ_SERVER_JAVA_OPTS"
debug_msg "RHQ_SERVER_ADDITIONAL_JAVA_OPTS: $RHQ_SERVER_ADDITIONAL_JAVA_OPTS"
# standalone.sh wants the options to be in the JAVA_OPTS variable
JAVA_OPTS="$RHQ_SERVER_JAVA_OPTS $RHQ_SERVER_ADDITIONAL_JAVA_OPTS"
export JAVA_OPTS
# ----------------------------------------------------------------------
# Prepare the command line arguments passed to the RHQ Server JBossAS
# standalone.sh script
# ----------------------------------------------------------------------
if [ -z "$RHQ_SERVER_CMDLINE_OPTS" ]; then
_PROPS_FILE_PATH="${RHQ_SERVER_HOME}/bin/rhq-server.properties"
# convert paths if we are on Windows
if [ -n "$_CYGWIN" ]; then
_PROPS_FILE_PATH=`cygpath --windows --path "$_PROPS_FILE_PATH"`
fi
RHQ_SERVER_CMDLINE_OPTS="-P ${_PROPS_FILE_PATH}"
fi
debug_msg "RHQ_SERVER_CMDLINE_OPTS: $RHQ_SERVER_CMDLINE_OPTS"
debug_msg "RHQ_SERVER_ADDITIONAL_CMDLINE_OPTS: $RHQ_SERVER_ADDITIONAL_CMDLINE_OPTS"
# JBoss may parse its command line args such that later options of a
# certain type may override earlier options of that same type, so make sure the
# additional opts are added after the base opts, since we want the additional
# opts to take precedence
_CMDLINE_OPTS="$RHQ_SERVER_CMDLINE_OPTS $RHQ_SERVER_ADDITIONAL_CMDLINE_OPTS"
# ----------------------------------------------------------------------
# We need to add our own modules to the core set of JBossAS modules.
# JBOSS_MODULEPATH tells standalone.sh what to use.
# ----------------------------------------------------------------------
_RHQ_MODULES_PATH="${RHQ_SERVER_HOME}/modules"
_INTERNAL_MODULES_PATH="${RHQ_SERVER_JBOSS_HOME}/modules"
if [ -n "$_CYGWIN" ]; then
_RHQ_MODULES_PATH=`cygpath --windows --path "$_RHQ_MODULES_PATH"`
_INTERNAL_MODULES_PATH=`cygpath --windows --path "$_INTERNAL_MODULES_PATH"`
fi
JBOSS_MODULEPATH="${_RHQ_MODULES_PATH}:${_INTERNAL_MODULES_PATH}"
export JBOSS_MODULEPATH
debug_msg "JBOSS_MODULEPATH: $JBOSS_MODULEPATH"
# ----------------------------------------------------------------------
# Now find the JBossAS standalone.sh script
# ----------------------------------------------------------------------
_JBOSS_RUN_SCRIPT="${RHQ_SERVER_JBOSS_HOME}/bin/standalone.sh"
if [ ! -f "$_JBOSS_RUN_SCRIPT" ]; then
echo "ERROR! Cannot find the JBossAS run script"
echo "Not found: $_JBOSS_RUN_SCRIPT"
exit 1
fi
debug_msg "_JBOSS_RUN_SCRIPT: $_JBOSS_RUN_SCRIPT"
# ----------------------------------------------------------------------
# Define where we want to write the pidfiles - let user override the dir
# Note that we actually have two pidfiles - one is for the script
# that starts the JBossAS Java virtual machine and the second is the
# actual server's Java virtual machine process itself.
# ----------------------------------------------------------------------
if [ -z "$RHQ_SERVER_PIDFILE_DIR" ]; then
RHQ_SERVER_PIDFILE_DIR="${RHQ_SERVER_HOME}/bin/internal"
fi
mkdir -p "$RHQ_SERVER_PIDFILE_DIR"
_SERVER_PIDFILE="${RHQ_SERVER_PIDFILE_DIR}/rhq-server.pid"
_JVM_PIDFILE="${RHQ_SERVER_PIDFILE_DIR}/rhq-jvm.pid"
# ----------------------------------------------------------------------
# Execute the command that the user wants us to do
# ----------------------------------------------------------------------
check_status "running"
case "$1" in
'console')
if [ "$_SERVER_RUNNING" = "1" ]; then
echo "$_SERVER_STATUS"
exit 0
fi
echo "Starting RHQ Server in console..."
# we are running in foreground, make both pids show the same process
echo "$$" > "$_SERVER_PIDFILE"
echo "$$" > "$_JVM_PIDFILE"
# START SERVER
# first, make sure its working directory is the JBossAS bin directory
cd "${RHQ_SERVER_JBOSS_HOME}/bin"
"$_JBOSS_RUN_SCRIPT" $_CMDLINE_OPTS
_JBOSS_STATUS=$?
remove_pid_files
exit $_JBOSS_STATUS
;;
'start')
if [ "$_SERVER_RUNNING" = "1" ]; then
echo "$_SERVER_STATUS"
exit 0
fi
echo "Trying to start the RHQ Server..."
LAUNCH_JBOSS_IN_BACKGROUND=true
JBOSS_PIDFILE="$_JVM_PIDFILE"
export LAUNCH_JBOSS_IN_BACKGROUND
export JBOSS_PIDFILE
# START SERVER
# first, make sure its working directory is the JBossAS bin directory
cd "${RHQ_SERVER_JBOSS_HOME}/bin"
if [ -n "$RHQ_SERVER_DEBUG" ] && [ "$RHQ_SERVER_DEBUG" != "false" ]; then
"$_JBOSS_RUN_SCRIPT" $_CMDLINE_OPTS > "${RHQ_SERVER_HOME}/logs/rhq-server.log" 2>&1 &
else
"$_JBOSS_RUN_SCRIPT" $_CMDLINE_OPTS > /dev/null 2>&1 &
fi
echo "$!" > "$_SERVER_PIDFILE"
sleep 5
check_status "starting"
echo "$_SERVER_STATUS"
if [ "$_SERVER_RUNNING" = "1" ]; then
exit 0
else
echo "Failed to start - make sure the RHQ Server is fully configured properly"
exit 1
fi
;;
'stop')
if [ "$_SERVER_RUNNING" = "0" ]; then
echo "$_SERVER_STATUS"
remove_pid_files
exit 0
fi
echo "Trying to stop the RHQ Server..."
echo "RHQ Server (pid=${_SERVER_PID}) is stopping..."
kill -TERM $_SERVER_PID
if [ -z "$RHQ_SERVER_STOP_DELAY" ]; then
# RHQ_SERVER_STOP_DELAY is not set
RHQ_SERVER_STOP_DELAY=5
fi
case $RHQ_SERVER_STOP_DELAY in
''|*[!0-9]*)
echo "RHQ_SERVER_STOP_DELAY is not a number (value=${RHQ_SERVER_STOP_DELAY})"
echo "Applying default value (5 minutes)"
RHQ_SERVER_STOP_DELAY=5
;;
*) ;;
esac
if [ $RHQ_SERVER_STOP_DELAY -le 0 ]; then
echo "RHQ_SERVER_STOP_DELAY is less than or equal to zero (value=${RHQ_SERVER_STOP_DELAY})"
echo "Applying default value (5 minutes)"
RHQ_SERVER_STOP_DELAY=5
fi
waited_seconds=0
max_wait_seconds=`expr $RHQ_SERVER_STOP_DELAY \* 60`
while [ "$_SERVER_RUNNING" -eq "1" ] && [ $waited_seconds -lt $max_wait_seconds ]; do
sleep 2
waited_seconds=`expr $waited_seconds + 2`
check_status "stopping..."
done
if [ "$_SERVER_RUNNING" = "0" ]; then
remove_pid_files
echo "RHQ Server has stopped."
exit 0
fi
debug_msg "RHQ Server did not stop within $RHQ_SERVER_STOP_DELAY minutes."
echo "Timed out waiting for RHQ Server to stop."
kill -QUIT $_SERVER_PID # Generate thread dump for later investigation
if [ -n "$RHQ_SERVER_KILL_AFTER_STOP_DELAY" ] && [ "$RHQ_SERVER_KILL_AFTER_STOP_DELAY" != "false" ]; then
kill_rhq_server
exit 0
else
echo "Failed to stop RHQ Server"
exit 127
fi
;;
'kill')
if [ "$_SERVER_RUNNING" = "0" ]; then
echo "$_SERVER_STATUS"
fi
if [ "$_JVM_RUNNING" = "0" ]; then
echo "$_JVM_STATUS"
remove_pid_files
exit 0
fi
kill_rhq_server
exit 0
;;
'clean')
if [ "$_SERVER_RUNNING" = "1" ]; then
echo "$_SERVER_STATUS"
echo "Please shutdown the server before cleaning."
exit 1
fi
echo "Cleaning data, tmp and log directories..."
rm -rf "${RHQ_SERVER_JBOSS_HOME}/standalone/data"
rm -rf "${RHQ_SERVER_JBOSS_HOME}/standalone/tmp"
rm -rf "${RHQ_SERVER_HOME}/logs"
;;
'status')
echo "$_SERVER_STATUS"
echo "$_JVM_STATUS"
if [ "$_SERVER_RUNNING" = "0" ] || [ "$_JVM_RUNNING" = 0 ]; then
exit 3
fi
exit 0
;;
*)
echo "Usage: $0 { start | stop | kill | status | console | clean }"
exit 1
;;
esac