This file is indexed.

/usr/lib/ocf/resource.d/heartbeat/jboss is in resource-agents 1:3.9.7-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
#!/bin/sh
#
# Description:  Manages a Jboss Server as an OCF High-Availability
#               resource under Heartbeat/LinuxHA control
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  
# 02110-1301, USA.
#
# Copyright (c) 2009 Bauer Systems KG / Stefan Schluppeck
#
#######################################################################
# OCF parameters:
#   OCF_RESKEY_resource_name - The name of the resource. Default is ${OCF_RESOURCE_INSTANCE}
#   OCF_RESKEY_jboss_version - The version of JBoss. Default is 5.
# why not let the RA log through lrmd?
# 2009/09/09 Nakahira:
# jboss_console is used to record output of the "run.sh".
# The log of "Run.sh" should not be output to ha-log because it is so annoying.
#   OCF_RESKEY_console - A destination of the log of jboss run and shutdown script. Default is /var/log/${OCF_RESKEY_resource_name}.log
#   OCF_RESKEY_shutdown_timeout - Time-out at the time of the stop. Default is 5
#   OCF_RESKEY_kill_timeout - The re-try number of times awaiting a stop. Default is 10
#   OCF_RESKEY_user - A user name to start a JBoss. Default is root
#   OCF_RESKEY_statusurl - URL for state confirmation. Default is ${OCF_RESKEY_statusurl_default}
#   OCF_RESKEY_java_home - Home directory of the Java. Default is ${JAVA_HOME}
#   OCF_RESKEY_java_opts - Options for Java.
#   OCF_RESKEY_jboss_home - Home directory of Jboss. Default is None
# is it possible to devise this string from options? I'm afraid
# that allowing users to set this could be error prone.
# 2009/09/09 Nakahira:
# It is difficult to set it automatically because jboss_pstring
# greatly depends on the environment. At any rate, system architect
# should note that pstring doesn't influence other processes.
#   OCF_RESKEY_jboss_base_dir - Base directory of JBoss. Default is ${OCF_RESKEY_jboss_base_dir_default}
#   OCF_RESKEY_pstring - String Jboss will found in procceslist. Default is ${OCF_RESKEY_pstring_default}
#   OCF_RESKEY_run_command - JBoss start command. Default is "${OCF_RESKEY_run_command_default}"
#   OCF_RESKEY_run_opts - Options for jboss to run. Default is ${OCF_RESKEY_run_opts_default}
#   OCF_RESKEY_shutdown_opts - Options for jboss to shutdonw. Default is "-s 127.0.0.1:1099"
#   OCF_RESKEY_rotate_consolelog - Control console log logrotation flag. Default is false.
#   OCF_RESKEY_rotate_value - console log logrotation value. Default is 86400 span(seconds).
#   OCF_RESKEY_rotate_logsuffix - Control console log logrotation suffix. Default is .%F.
###############################################################################


: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs

usage()
{
    cat <<-!
usage: $0 action

action:
        start   start jboss

        stop    stop the jboss

        status  return the status of jboss, run or down

        monitor  return TRUE if the jboss appears to be working.
                 You have to have installed $WGETNAME for this to work.

        meta-data       show meta data message

        validate-all    validate the instance parameters
!
    return $OCF_ERR_ARGS
}

isrunning_jboss()
{
    local rc
    if [ -z "$1" ];then
        ocf_run -q -err wget -t 1 -O /dev/null $STATUSURL
    else
        # Retry message for restraint
        wget -t 1 -O /dev/null $STATUSURL 2>/dev/null
    fi
    rc=$?
    if [ $rc -eq 0 ]; then
        return $OCF_SUCCESS
    fi
    # JBoss service error
    return $OCF_ERR_GENERIC
}

monitor_rotatelogs()
{
    pgrep -f "$ROTATELOGS.*$CONSOLE$ROTATELOG_SUFFIX" > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        ocf_log warn "A rotatelogs command for $CONSOLE is not running. Restarting it."
        start_rotatelogs
        if [ $? -eq 0 ]; then
            ocf_log info "Restart rotatelogs process succeeded."
        else
            ocf_log warn "Restart rotatelogs process failed."
        fi
    fi
}

monitor_jboss()
{
    if ! pgrep -f "$PSTRING" > /dev/null; then
        return $OCF_NOT_RUNNING
    fi
    isrunning_jboss $1
    rc=$?
    if [ $rc -ne $OCF_SUCCESS ]; then
        return $rc
    fi
    if ocf_is_true $ROTATELOG_FLG; then
       # Monitor rotatelogs process and restart it if it is stopped.
       # And never consider rotatelogs process failure to be a monitor failure
       # as long as JBoss process works fine.
       monitor_rotatelogs
    fi
    return $OCF_SUCCESS
}

start_rotatelogs()
{
    su - -s /bin/sh $JBOSS_USER \
        -c "$ROTATELOGS -l \"$CONSOLE$ROTATELOG_SUFFIX\" $ROTATEVALUE" \
        < "$CONSOLE" > /dev/null 2>&1 &
}

rotate_console()
{
    # Check $CONSOLE$ROTATELOG_SUFFIX is writable or not.
    CURRENT_ROTATELOG_SUFFIX=`date +"$ROTATELOG_SUFFIX"`
    su - -s /bin/sh $JBOSS_USER \
        -c "touch \"$CONSOLE$CURRENT_ROTATELOG_SUFFIX\"" > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        ocf_log err "$CONSOLE$CURRENT_ROTATELOG_SUFFIX is not writable."
        return $OCF_ERR_GENERIC
    fi

    # Clean up and set permissions on required files
    if [ -p "$CONSOLE" ]; then
        rm -rf "$CONSOLE"
    elif [ -e "$CONSOLE" ]; then
        DATE=`date +"%F-%H%M%S"`
        ocf_log warn "$CONSOLE already exists. It is saved as $CONSOLE-$DATE"
        mv "$CONSOLE" "$CONSOLE-$DATE"
    fi
    mkfifo -m700 "$CONSOLE"
    chown --dereference "$JBOSS_USER" "$CONSOLE" || true

    start_rotatelogs
}

start_jboss()
{
    monitor_jboss start
    if [ $? -eq $OCF_SUCCESS ]; then
        ocf_log info "JBoss already running."
        return $OCF_SUCCESS
    fi

    if ocf_is_true $ROTATELOG_FLG; then
        rotate_console
        if [ $? -eq 0 ]; then
            ocf_log debug "Rotate console log succeeded."
        else
            ocf_log err "Rotate console log failed. Avoid starting jboss without console log rotation."
            return $OCF_ERR_GENERIC
        fi
    fi

    ocf_log info "Starting JBoss[$RESOURCE_NAME]"
    if [ "$JBOSS_USER" = root ]; then
        "$RUN_COMMAND" $RUN_OPTS \
            >> "$CONSOLE" 2>&1 &
    else
        su - -s /bin/sh "$JBOSS_USER" \
            -c "export JAVA_HOME=\"${JAVA_HOME}\"; \
                export JAVA_OPTS=\"${JAVA_OPTS}\"; \
                export JBOSS_HOME=\"${JBOSS_HOME}\"; \
                export JBOSS_BASE_DIR=\"${JBOSS_BASE_DIR}\"; \
                \"$RUN_COMMAND\" $RUN_OPTS" \
            >> "$CONSOLE" 2>&1 &
    fi

    while true; do
        monitor_jboss start
        if [ $? -eq $OCF_SUCCESS ]; then
            break
        fi
        ocf_log info "start_jboss[$RESOURCE_NAME]: retry monitor_jboss"
        sleep 3
    done

    ocf_log info "JBoss[$RESOURCE_NAME] is started."
    return $OCF_SUCCESS
}

output_thread_dump()
{
    ocf_log info "stop_jboss[$RESOURCE_NAME]: output a JVM thread dump to $CONSOLE"
    pkill -QUIT -f "$PSTRING"
}

# arg1 : timeout
# arg2 : send specified signal
wait_process_exit()
{
    local lapse_sec=0
    local timeout=$1
    local signal=$2

    while pgrep -f "$PSTRING" > /dev/null; do
        sleep 1
        lapse_sec=`expr $lapse_sec + 1`
        if [ -n "$signal" ]; then
            ocf_log info "stop_jboss[$RESOURCE_NAME]: kill jboss by SIG$signal ($lapse_sec/$timeout)"
            pkill -$signal -f "$PSTRING"
        else
            ocf_log info "stop_jboss[$RESOURCE_NAME]: stop NORM $lapse_sec/$timeout"
        fi
        if [ "$timeout" -ne 0 -a $lapse_sec -ge $timeout ]; then
            return 1
        fi
    done
    return 0
}

stop_jboss5()
{
    if [ "$JBOSS_USER" = root ]; then
        "$JBOSS_HOME/bin/shutdown.sh" $SHUTDOWN_OPTS -S \
            >> "$CONSOLE" 2>&1 &
    else
        su - -s /bin/sh "$JBOSS_USER" \
            -c "export JAVA_HOME=\"${JAVA_HOME}\"; \
                export JBOSS_HOME=\"${JBOSS_HOME}\"; \
                \"$JBOSS_HOME/bin/shutdown.sh\" $SHUTDOWN_OPTS -S" \
            >> "$CONSOLE" 2>&1 &
    fi
    if ! wait_process_exit $SHUTDOWN_TIMEOUT; then
        output_thread_dump
        if ! wait_process_exit $KILL_TIMEOUT TERM; then
            return 1
        fi
    fi
    return 0
}

stop_jboss6()
{
    pkill -TERM -f "$PSTRING"

    if ! wait_process_exit $SHUTDOWN_TIMEOUT; then
        output_thread_dump
        return 1
    fi
    return 0
}

stop_jboss()
{
    local rc

    if ! pgrep -f "$PSTRING" > /dev/null; then
        ocf_log info "JBoss[$RESOURCE_NAME] is already stopped."
    else
        ocf_log info "Stopping JBoss[$RESOURCE_NAME]"
        # JBoss5 : shutdonw.sh -> SIGQUIT(output thread dump) -> SIGTERM
        #   If the JBoss process hangs, JBoss RA waits $SHUTDOWN_TIMEOUT
        #   seconds and tries kill TERM and QUIT for $KILL_TIMEOUT seconds.
        # JBoss6 : SIGTERM -> SIGQUIT(output thread dump)
        #   If the JBoss process hangs, JBoss RA waits $SHUTDOWN_TIMEOUT
        #   seconds and tries kill QUIT.
        if [ "$JBOSS_VERSION" -le 5 ]; then
            stop_jboss5
            rc=$?
        else
            stop_jboss6
            rc=$?
        fi
        if [ $rc -ne 0 ]; then
            # JBoss5
            #   The stop timeout of RA should be
            #   longer than $SHUTDOWN_TIMEOUT + $KILL_TIMEOUT.
            # JBoss6
            #   The stop timeout of RA should be longer than $SHUTDOWN_TIMEOUT.
            wait_process_exit 0 KILL
        fi
        ocf_log info "JBoss[$RESOURCE_NAME] is stopped."
    fi

    if ocf_is_true $ROTATELOG_FLG; then
        rm -f "${CONSOLE}"
    fi

    return $OCF_SUCCESS
}

status_jboss()
{
    if ! pgrep -f "$PSTRING" > /dev/null; then
        echo "JBoss process[$RESOURCE_NAME] is not running."
        return $OCF_NOT_RUNNING
    fi

    if isrunning_jboss; then
        echo "JBoss[$RESOURCE_NAME] is running."
        return $OCF_SUCCESS
    else
        echo "JBoss process[$RESOURCE_NAME] is running."
        echo "But, we can not access JBoss web service."
        return $OCF_NOT_RUNNING
    fi
}


metadata_jboss()
{
    cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="jboss">
<version>1.0</version>

<longdesc lang="en">
Resource script for Jboss. It manages a Jboss instance as an HA resource.
</longdesc>
<shortdesc lang="en">Manages a JBoss application server instance</shortdesc>

<parameters>

<parameter name="jboss_version" unique="0" required="0">
<longdesc lang="en">
The version of JBoss. Default is 5.
The usage of JBoss was greatly changed as of JBoss 6.
Specify "6" when you use JBoss 6.
</longdesc>
<shortdesc>The version of JBoss</shortdesc>
<content type="integer" default="5" />
</parameter>

<parameter name="resource_name" unique="1" required="0">
<longdesc lang="en">
The name of the resource. Defaults to the name of the resource
instance.
</longdesc>
<shortdesc>The name of the resource</shortdesc>
<content type="string" default="${OCF_RESOURCE_INSTANCE}" />
</parameter>

<parameter name="console" unique="1" required="0">
<longdesc lang="en">
A destination of the log of jboss run and shutdown script.
</longdesc>
<shortdesc>jboss log path</shortdesc>
<content type="string" default="" />
</parameter>

<parameter name="shutdown_timeout" unique="0" required="0">
<longdesc lang="en">
Timeout for jboss bin/shutdown.sh. We wait for this timeout to
expire, then send the TERM and QUIT signals. Finally, the KILL
signal is used to terminate the jboss process. You should set the
timeout for the stop operation to a value bigger than the sum of
the timeout parameters. See also kill_timeout.
</longdesc>
<shortdesc>shutdown timeout</shortdesc>
<content type="integer" default="5" />
</parameter>

<parameter name="kill_timeout" unique="0" required="0">
<longdesc lang="en">
If bin/shutdown.sh doesn't stop the jboss process, then we send
it TERM and QUIT signals, intermittently and once a second. After
this timeout expires, if the process is still live, we use the
KILL signal. See also shutdown_timeout.
</longdesc>
<shortdesc>stop by signal timeout</shortdesc>
<content type="integer" default="10" />
</parameter>

<parameter name="user" unique="0" required="0">
<longdesc lang="en">
A user name to start a JBoss.
</longdesc>
<shortdesc>A user name to start a resource.</shortdesc>
<content type="string" default="root"/>
</parameter>

<parameter name="statusurl" unique="0" required="0">
<longdesc lang="en">
URL to test in the monitor operation.
</longdesc>
<shortdesc>URL to test in the monitor operation.</shortdesc>
<content type="string" default="${OCF_RESKEY_statusurl_default}" />
</parameter>

<parameter name="java_home" unique="0" required="0">
<longdesc lang="en">
Home directory of Java. Defaults to the environment variable
JAVA_HOME. If it is not set, then define this parameter.
</longdesc>
<shortdesc>Home directory of Java.</shortdesc>
<content type="string" default="$JAVA_HOME"/>
</parameter>

<parameter name="java_opts" unique="0" required="0">
<longdesc lang="en">
Java options.
</longdesc>
<shortdesc>Java options.</shortdesc>
<content type="string" default=""/>
</parameter>

<parameter name="jboss_home" unique="0" required="1">
<longdesc lang="en">
Home directory of Jboss.
</longdesc>
<shortdesc>Home directory of Jboss.</shortdesc>
<content type="string" default=""/>
</parameter>

<parameter name="jboss_base_dir" unique="0" required="0">
<longdesc lang="en">
Base directory of JBoss. This parameter is not used in JBoss5.
</longdesc>
<shortdesc>Base directory of JBoss.</shortdesc>
<content type="string" default="${OCF_RESKEY_jboss_base_dir_default}" />
</parameter>

<parameter name="pstring" unique="0" required="0">
<longdesc lang="en">
With this string heartbeat matches for the right process to kill.
</longdesc>
<shortdesc>pkill/pgrep search string</shortdesc>
<content type="string" default="${OCF_RESKEY_pstring_default}" />
</parameter>

<parameter name="run_command" unique="0" required="0">
<longdesc lang="en">
JBoss start command.
</longdesc>
<shortdesc>JBoss start command.</shortdesc>
<content type="string" default="${OCF_RESKEY_run_command_default}" />
</parameter>

<parameter name="run_opts" unique="0" required="0">
<longdesc lang="en">
Start options to start Jboss with, defaults are from the Jboss-Doku.
</longdesc>
<shortdesc>options for jboss run.sh</shortdesc>
<content type="string" default="${OCF_RESKEY_run_opts_default}" />
</parameter>

<parameter name="shutdown_opts" unique="0" required="0">
<longdesc lang="en">
Stop options to stop Jboss with.
</longdesc>
<shortdesc>options for jboss shutdown.sh</shortdesc>
<content type="string" default="-s 127.0.0.1:1099" />
</parameter>

<parameter name="rotate_consolelog" unique="0">
<longdesc lang="en">
Rotate console log flag.
</longdesc>
<shortdesc>Rotate console log flag</shortdesc>
<content type="boolean" default="false" />
</parameter>

<parameter name="rotate_value" unique="0">
<longdesc lang="en">
Console log rotation value (default is 86400 seconds).
</longdesc>
<shortdesc>Console log rotation value (default is 86400 seconds)</shortdesc>
<content type="integer" default="86400" />
</parameter>

<parameter name="rotate_logsuffix" unique="0">
<longdesc lang="en">
Rotate console log suffix.
</longdesc>
<shortdesc>Rotate console log suffix</shortdesc>
<content type="integer" default=".%F" />
</parameter>

</parameters>

<actions>
<action name="start" timeout="60s" />
<action name="stop" timeout="120s" />
<action name="status" timeout="30s" />
<action name="monitor" depth="0" timeout="30s" interval="10s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all"  timeout="5"/>
</actions>
</resource-agent>
END
    return $OCF_SUCCESS
}

validate_all_jboss()
{
    if [ ! -d "$JAVA_HOME" ]; then
        ocf_log err "JAVA_HOME does not exist."
        return $OCF_ERR_INSTALLED
    fi

    if [ ! -d "$JBOSS_HOME" ]; then
        ocf_log err "JBOSS_HOME does not exist."
        return $OCF_ERR_INSTALLED
    fi

    if [ "$JBOSS_VERSION" -gt 5 ]; then
        if [ ! -d "$JBOSS_BASE_DIR" ]; then
            ocf_log err "JBOSS_BASE_DIR does not exist."
            return $OCF_ERR_INSTALLED
        fi
    fi

    if [ ! -x "$JAVA" ]; then
        ocf_log err "java command does not exist."
        return $OCF_ERR_INSTALLED
    fi

    if ocf_is_true $ROTATELOG_FLG; then
        if [ ! -x "$ROTATELOGS" ]; then
            ocf_log err "rotatelogs command does not exist."
            return $OCF_ERR_INSTALLED
        fi
    fi

    return $OCF_SUCCESS
}

COMMAND=$1
JBOSS_VERSION="${OCF_RESKEY_jboss_version-5}"
if ! ocf_is_decimal $JBOSS_VERSION; then
    ocf_log err "Invalid parameter value: jboss_version [$JBOSS_VERSION]"
    return $OCF_ERR_ARGS
fi
# Setting of the default value
if [ "$JBOSS_VERSION" -le 5 ]; then
    OCF_RESKEY_statusurl_default="http://127.0.0.1:8080"
    OCF_RESKEY_pstring_default="java -Dprogram.name=run.sh"
    OCF_RESKEY_run_command_default="${OCF_RESKEY_jboss_home}/bin/run.sh"
    OCF_RESKEY_run_opts_default="-c default"
else
    OCF_RESKEY_jboss_base_dir_default="${OCF_RESKEY_jboss_home}/standalone"
    JBOSS_BASE_DIR="${OCF_RESKEY_jboss_base_dir-${OCF_RESKEY_jboss_base_dir_default}}"
    OCF_RESKEY_statusurl_default="http://127.0.0.1:9990"
    OCF_RESKEY_pstring_default="java.*-Djboss.server.base.dir=${JBOSS_BASE_DIR}( .*)?$"
    OCF_RESKEY_run_command_default="${OCF_RESKEY_jboss_home}/bin/standalone.sh"
    OCF_RESKEY_run_opts_default=""
fi
RESOURCE_NAME="${OCF_RESKEY_resource_name-${OCF_RESOURCE_INSTANCE}}"
CONSOLE="${OCF_RESKEY_console-/var/log/${RESOURCE_NAME}.log}"
SHUTDOWN_TIMEOUT="${OCF_RESKEY_shutdown_timeout-5}"
KILL_TIMEOUT="${OCF_RESKEY_kill_timeout-10}"
JBOSS_USER="${OCF_RESKEY_user-root}"
STATUSURL="${OCF_RESKEY_statusurl-${OCF_RESKEY_statusurl_default}}"
PSTRING="${OCF_RESKEY_pstring-${OCF_RESKEY_pstring_default}}"
RUN_OPTS="${OCF_RESKEY_run_opts-${OCF_RESKEY_run_opts_default}}"
SHUTDOWN_OPTS="${OCF_RESKEY_shutdown_opts--s 127.0.0.1:1099}"
ROTATELOG_FLG="${OCF_RESKEY_rotate_consolelog-false}"
ROTATEVALUE="${OCF_RESKEY_rotate_value-86400}"
ROTATELOG_SUFFIX="${OCF_RESKEY_rotate_logsuffix-.%F}"

if [ $# -ne 1 ]; then
    usage
    exit $OCF_ERR_ARGS
fi

if [ "$COMMAND" = "meta-data" ]; then
    metadata_jboss
    exit $OCF_SUCCESS
fi
if [ "$COMMAND" = "help" -o "$COMMAND" = "usage" ]; then
    usage
    exit $OCF_SUCCESS
fi

# test if these two are set and if directories exist and if the
# required scripts/binaries exist; use OCF_ERR_INSTALLED
JAVA_HOME="${OCF_RESKEY_java_home-${JAVA_HOME}}"
JAVA_OPTS="${OCF_RESKEY_java_opts}"
JBOSS_HOME="${OCF_RESKEY_jboss_home}"
RUN_COMMAND="${OCF_RESKEY_run_command-${OCF_RESKEY_run_command_default}}"

LSB_STATUS_STOPPED=3

export JAVA_HOME JAVA_OPTS JBOSS_HOME JBOSS_BASE_DIR

JAVA=${JAVA_HOME}/bin/java

ROTATELOGS=""
if ocf_is_true $ROTATELOG_FLG; then
    # Look for rotatelogs/rotatelogs2
    if [ -x /usr/sbin/rotatelogs ]; then
        ROTATELOGS=/usr/sbin/rotatelogs
    elif [ -x /usr/sbin/rotatelogs2 ]; then
        ROTATELOGS=/usr/sbin/rotatelogs2
    fi
fi

validate_all_jboss
rc=$?

[ "$COMMAND" = "validate-all" ] && exit $rc

if [ $rc -ne 0 ]; then
    case $COMMAND in
        stop)       exit    $OCF_SUCCESS;;
        monitor)    exit    $OCF_NOT_RUNNING;;
        status)     exit    $LSB_STATUS_STOPPED;;
        *)          exit    $rc;;
    esac
fi

case "$COMMAND" in
    start)
        start_jboss
        func_status=$?
        exit $func_status
        ;;
    stop)
        stop_jboss
        func_status=$?
        exit $func_status
        ;;
    status)
        status_jboss
        exit $?
        ;;
    monitor)
        monitor_jboss
        func_status=$?
        exit $func_status
        ;;
    validate-all)
        validate_all_jboss
        exit $?
        ;;
    *)
        usage
        exit $OCF_ERR_UNIMPLEMENTED;;
esac