diff --git a/heartbeat/jboss b/heartbeat/jboss index a1b662130..0606744e3 100755 --- a/heartbeat/jboss +++ b/heartbeat/jboss @@ -1,505 +1,505 @@ #!/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} # 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 http://127.0.0.1:8080 # 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_pstring - String Jboss will found in procceslist. Default is "java -Dprogram.name=run.sh" # OCF_RESKEY_run_opts - Options for jboss to run. Default is "-c 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() +usage() { - cat <<-! + 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 + 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 + 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_jboss() { - if ! pgrep -f "$PSTRING" > /dev/null; then - return $OCF_NOT_RUNNING - fi - isrunning_jboss $1 + if ! pgrep -f "$PSTRING" > /dev/null; then + return $OCF_NOT_RUNNING + fi + isrunning_jboss $1 } rotate_console() { - # Look for rotatelogs/rotatelogs2 - if [ -x /usr/sbin/rotatelogs ]; then - ROTATELOGS=/usr/sbin/rotatelogs - elif [ -x /usr/sbin/rotatelogs2 ]; then - ROTATELOGS=/usr/sbin/rotatelogs2 - else - ocf_log warn "rotatelogs command not found." - return 1 - fi - - # Clean up and set permissions on required files - rm -rf "$CONSOLE" - mkfifo -m700 "$CONSOLE" - chown --dereference "$JBOSS_USER" "$CONSOLE" || true - - su - -s /bin/sh $JBOSS_USER \ - -c "$ROTATELOGS -l \"$CONSOLE$ROTATELOG_SUFFIX\" $ROTATEVALUE" \ - < "$CONSOLE" > /dev/null 2>&1 & + # Look for rotatelogs/rotatelogs2 + if [ -x /usr/sbin/rotatelogs ]; then + ROTATELOGS=/usr/sbin/rotatelogs + elif [ -x /usr/sbin/rotatelogs2 ]; then + ROTATELOGS=/usr/sbin/rotatelogs2 + else + ocf_log warn "rotatelogs command not found." + return 1 + fi + + # Clean up and set permissions on required files + rm -rf "$CONSOLE" + mkfifo -m700 "$CONSOLE" + chown --dereference "$JBOSS_USER" "$CONSOLE" || true + + su - -s /bin/sh $JBOSS_USER \ + -c "$ROTATELOGS -l \"$CONSOLE$ROTATELOG_SUFFIX\" $ROTATEVALUE" \ + < "$CONSOLE" > /dev/null 2>&1 & } start_jboss() { - monitor_jboss start - if [ $? = $OCF_SUCCESS ]; then - ocf_log info "JBoss already running." - return $OCF_SUCCESS - fi - - if ocf_is_true $ROTATELOG_FLG; then - rotate_console - if [ $? = 0 ]; then - ocf_log debug "Rotate console log succeeded." - else - ocf_log warn "Rotate console log failed. Starting jboss without console log rotation." - fi - fi - - ocf_log info "Starting JBoss[$RESOURCE_NAME]" - if [ "$JBOSS_USER" = root ]; then - "$JBOSS_HOME/bin/run.sh" $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}\"; \ - \"$JBOSS_HOME/bin/run.sh\" $RUN_OPTS" \ - >> "$CONSOLE" 2>&1 & - fi - - while true; do - monitor_jboss start - if [ $? = $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 + monitor_jboss start + if [ $? = $OCF_SUCCESS ]; then + ocf_log info "JBoss already running." + return $OCF_SUCCESS + fi + + if ocf_is_true $ROTATELOG_FLG; then + rotate_console + if [ $? = 0 ]; then + ocf_log debug "Rotate console log succeeded." + else + ocf_log warn "Rotate console log failed. Starting jboss without console log rotation." + fi + fi + + ocf_log info "Starting JBoss[$RESOURCE_NAME]" + if [ "$JBOSS_USER" = root ]; then + "$JBOSS_HOME/bin/run.sh" $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}\"; \ + \"$JBOSS_HOME/bin/run.sh\" $RUN_OPTS" \ + >> "$CONSOLE" 2>&1 & + fi + + while true; do + monitor_jboss start + if [ $? = $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" + 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 + if [ "$timeout" -ne 0 -a $lapse_sec -ge $timeout ]; then return 1 - fi + fi done return 0 } stop_jboss() { - ocf_log info "Stopping JBoss[$RESOURCE_NAME]" - - if ! pgrep -f "$PSTRING" > /dev/null; then - ocf_log info "JBoss[$RESOURCE_NAME] is already stopped." - else - 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 - # If the JBoss process hangs, JBoss RA waits $SHUTDOWN_TIMEOUT - # seconds and tries kill TERM and QUIT for $KILL_TIMEOUT seconds. - # The stop timeout of RA should be - # longer than $SHUTDOWN_TIMEOUT + $KILL_TIMEOUT. - wait_process_exit 0 KILL - fi - fi - fi - - if ocf_is_true $ROTATELOG_FLG; then - rm -f "${CONSOLE}" + ocf_log info "Stopping JBoss[$RESOURCE_NAME]" + + if ! pgrep -f "$PSTRING" > /dev/null; then + ocf_log info "JBoss[$RESOURCE_NAME] is already stopped." + else + 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 + # If the JBoss process hangs, JBoss RA waits $SHUTDOWN_TIMEOUT + # seconds and tries kill TERM and QUIT for $KILL_TIMEOUT seconds. + # The stop timeout of RA should be + # longer than $SHUTDOWN_TIMEOUT + $KILL_TIMEOUT. + wait_process_exit 0 KILL + fi + fi + fi + + if ocf_is_true $ROTATELOG_FLG; then + rm -f "${CONSOLE}" + fi - ocf_log info "JBoss[$RESOURCE_NAME] is stopped." - return $OCF_SUCCESS + ocf_log info "JBoss[$RESOURCE_NAME] is stopped." + 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 + 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 < 1.0 Resource script for Jboss. It manages a Jboss instance as an HA resource. Manages a JBoss application server instance The name of the resource. Defaults to the name of the resource instance. The name of the resource A destination of the log of jboss run and shutdown script. jboss log path 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. shutdown timeout 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. stop by signal timeout A user name to start a JBoss. A user name to start a resource. URL to test in the monitor operation. URL to test in the monitor operation. Home directory of Java. Defaults to the environment variable JAVA_HOME. If it is not set, then define this parameter. Home directory of Java. Java options. Java options. Home directory of Jboss. Home directory of Jboss. With this string heartbeat matches for the right process to kill. pkill/pgrep search string Start options to start Jboss with, defaults are from the Jboss-Doku. options for jboss run.sh Stop options to stop Jboss with. options for jboss shutdown.sh Rotate console log flag. Rotate console log flag Console log rotation value (default is 86400 seconds). Console log rotation value (default is 86400 seconds) Rotate console log suffix. Rotate console log suffix END - return $OCF_SUCCESS + return $OCF_SUCCESS } validate_all_jboss() { - ocf_log info "validate_all_jboss[$RESOURCE_NAME]" - return $OCF_SUCCESS + ocf_log info "validate_all_jboss[$RESOURCE_NAME]" + return $OCF_SUCCESS } COMMAND=$1 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-http://127.0.0.1:8080}" PSTRING="${OCF_RESKEY_pstring-java -Dprogram.name=run.sh}" RUN_OPTS="${OCF_RESKEY_run_opts--c 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 + usage + exit $OCF_ERR_ARGS fi if [ "$COMMAND" = "meta-data" ]; then - metadata_jboss - exit $OCF_SUCCESS + metadata_jboss + exit $OCF_SUCCESS fi if [ "$COMMAND" = "help" -o "$COMMAND" = "usage" ]; then - usage - exit $OCF_SUCCESS + 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}" LSB_STATUS_STOPPED=3 if [ ! -d "$JAVA_HOME" -o ! -d "$JBOSS_HOME" ]; then - case $COMMAND in - stop) exit $OCF_SUCCESS;; - monitor) exit $OCF_NOT_RUNNING;; - status) exit $LSB_STATUS_STOPPED;; - esac - ocf_log err "JAVA_HOME or JBOSS_HOME does not exist." - exit $OCF_ERR_INSTALLED + case $COMMAND in + stop) exit $OCF_SUCCESS;; + monitor) exit $OCF_NOT_RUNNING;; + status) exit $LSB_STATUS_STOPPED;; + esac + ocf_log err "JAVA_HOME or JBOSS_HOME does not exist." + exit $OCF_ERR_INSTALLED fi export JAVA_HOME JAVA_OPTS JBOSS_HOME JAVA=${JAVA_HOME}/bin/java if [ ! -x "$JAVA" ]; then - case $COMMAND in - stop) exit $OCF_SUCCESS;; - monitor) exit $OCF_NOT_RUNNING;; - status) exit $LSB_STATUS_STOPPED;; - esac - ocf_log err "java command does not exist." - exit $OCF_ERR_INSTALLED + case $COMMAND in + stop) exit $OCF_SUCCESS;; + monitor) exit $OCF_NOT_RUNNING;; + status) exit $LSB_STATUS_STOPPED;; + esac + ocf_log err "java command does not exist." + exit $OCF_ERR_INSTALLED 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;; + 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