Hi Kazutomo-san,

On Wed, Sep 09, 2009 at 02:46:52PM +0900, NAKAHIRA Kazutomo wrote:
> Hi, Dejan
> 
> I'm sorry I didn't get back to you sooner.
> I took over takenaka-san's work.
> 
> I corrected a JBoss RA referring to your comments.
> The modification and my comments is written in the attached patch.

Many thanks for your work.

I made some changes and the result is attached. The changes are
mainly in the documentation (meta-data). I also renamed the two
timeout parameters: this way your intention should be clearer.
There are other minor changes, please let me know if you find
anything wrong or not clear.

The stop procedure should be simplified by splitting the pkill
-TERM and pkill -QUIT parts into two sequential processes (not
interleaved as it is now). Then you could also make a short
function with signal and timeout as input.

The JAVA_HOME variable is sometimes already available in the
environment, perhaps that could be used instead of requiring that
the user sets that parameter.

I find the "jboss_" prefix for parameters superfluous, for
instance it should be just "name" and not "jboss_name" since it's
obvious that the parameter is in the jboss primitive, but I leave
that to you to decide.

Cheers,

Dejan

> Best Regards,
> NAKAHIRA Kazutomo
> 
> Dejan Muhamedagic wrote:
> > Hi Keisuke-san,
> > 
> > On Thu, Jun 11, 2009 at 07:06:42PM +0900, Keisuke MORI wrote:
> >> Hi,
> >>
> >> I'm posting an OCF RA for JBoss, which was originally posted by Stefan
> >> to the users list, and includes some modifications as suggested by
> >> Takenaka-san:
> >>
> >> http://www.gossamer-threads.com/lists/linuxha/users/53969
> >>
> >> Stefan,
> >> Do you have any comment on this modification?
> >>
> >> Dejan,
> >> Would you please review this RA if you have any chance?
> > 
> > Script with comments attached. And a bit to reiterate:
> > 
> > Why use resource specific logs? Shouldn't it be better to have
> > all in one place, i.e. wherever lrmd is logging (lrmd will catch
> > all stdin/stderr output). I don't know anything about jboss.
> > Perhaps it is common to log to a separate file. In particular if
> > the logging goes on while the process is running. It's just that
> > start/stop should probably leave some trace in lrmd logs.
> > 
> > This RA doesn't do enough validation for binaries, scripts, etc.
> > 
> > Cheers,
> > 
> > Dejan
> > 
> >> If you are all OK, I will commit the RA to the -dev repository.
> >>
> >> Thanks,
> >>
> >> -- 
> >> Keisuke MORI
> > 
> > 
> >> _______________________________________________________
> >> Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
> >> http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
> >> Home Page: http://linux-ha.org/
> > 
> > 
> > ------------------------------------------------------------------------
> > 
> > _______________________________________________________
> > Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
> > http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
> > Home Page: http://linux-ha.org/
> 
> 
> -- 
> ----------------------------------------
> NAKAHIRA Kazutomo
> NTT DATA INTELLILINK CORPORATION
> Open Source Business Unit
> Software Services Integration Business Division
#!/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_jboss_name - The name of the resource. Default is jboss
# 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_jboss_console  - A destination of the log of jboss run and 
shutdown script. Default /var/log/${OCF_RESKEY_jboss_name}.log
#   OCF_RESKEY_jboss_shutdown_timeout  - Time-out at the time of the stop. 
Default is 5
#   OCF_RESKEY_jboss_kill_timeout  - The re-try number of times awaiting a 
stop. Default is 10
#   OCF_RESKEY_jboss_user  - A user name to start a resource. 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 None
#   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_pstring - String Jboss will found in procceslist. Default 
is "java -Dprogram.name=run.sh"
#   OCF_RESKEY_jboss_run_opts - Options for jboss to run. Default is "-c 
default -l lpg4j"
#   OCF_RESKEY_jboss_shutdown_opts - Options for jboss to shutdonw. Default is 
"-s 127.0.0.1:1099"
###############################################################################


. ${OCF_ROOT}/resource.d/heartbeat/.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()
{
        if wget -O /dev/null $RESOURCE_STATUSURL 2>/dev/null; then
                return $OCF_SUCCESS
        fi
        # JBoss service error 
        return $OCF_ERR_GENERIC
}

monitor_jboss()
{
        if ! pgrep -f "$JBOSS_PSTRING" > /dev/null; then
                return $OCF_NOT_RUNNING
        fi
        isrunning_jboss
}

start_jboss()
{
        monitor_jboss
        if [ $? = $OCF_SUCCESS ]; then
                return $OCF_SUCCESS
        fi

        ocf_log info "Starting JBoss[$JBOSS_NAME]"
        if [ "$RESOURCE_JBOSS_USER" = root ]; then
                "$JBOSS_HOME/bin/run.sh" $JBOSS_RUN_OPTS \
                        >> "$JBOSS_CONSOLE" 2>&1 &
        else
                su - -s /bin/bash "$RESOURCE_JBOSS_USER" \
                        -c "export JAVA_HOME=${JAVA_HOME};\n
                            export JBOSS_HOME=${JBOSS_HOME};\n
                            $JBOSS_HOME/bin/run.sh $JBOSS_RUN_OPTS" \
                        >> "$JBOSS_CONSOLE" 2>&1 &
        fi

        while true; do
                monitor_jboss
                if [ $? = $OCF_SUCCESS ]; then
                        break
                fi
                ocf_log debug "start_jboss[$JBOSS_NAME]: retry monitor_jboss"
                sleep 3
        done

        return $OCF_SUCCESS
}

stop_jboss()
{
        ocf_log info "Stopping JBoss[$JBOSS_NAME]"

        if [ "$RESOURCE_JBOSS_USER" = root ]; then
                "$JBOSS_HOME/bin/shutdown.sh" $JBOSS_SHUTDOWN_OPTS -S \
                        >> "$JBOSS_CONSOLE" 2>&1 &
        else
                su - -s /bin/bash "$RESOURCE_JBOSS_USER" \
                        -c "export JAVA_HOME=${JAVA_HOME};\n
                            export JBOSS_HOME=${JBOSS_HOME};\n
                            $JBOSS_HOME/bin/shutdown.sh $JBOSS_SHUTDOWN_OPTS 
-S" \
                        >> "$JBOSS_CONSOLE" 2>&1 &

        fi

        lapse_sec=0
        while pgrep -f "$JBOSS_PSTRING" > /dev/null; do
                sleep 1
                lapse_sec=`expr $lapse_sec + 1`
                ocf_log info "stop_jboss[$JBOSS_NAME]: stop NORM 
$lapse_sec/$JBOSS_SHUTDOWN_TIMEOUT"
                if [ $lapse_sec -ge $JBOSS_SHUTDOWN_TIMEOUT ]; then
                        break
                fi
        done

        if pgrep -f "$JBOSS_PSTRING" > /dev/null; then
                lapse_sec=0
                while true; do
                        sleep 1
                        lapse_sec=`expr $lapse_sec + 1`
                        ocf_log info "stop_jboss[$JBOSS_NAME]: kill jboss by 
SIGTERM ($lapse_sec/$JBOSS_KILL_TIMEOUT)"
                        pkill -TERM -f "$JBOSS_PSTRING"
                        sleep 1
                        lapse_sec=`expr $lapse_sec + 1`
                        if pgrep -f "$JBOSS_PSTRING" > /dev/null; then
                                ocf_log info "stop_jboss[$JBOSS_NAME]: kill 
jboss by SIGQUIT ($lapse_sec/$JBOSS_KILL_TIMEOUT)"
                                pkill -QUIT -f "$JBOSS_PSTRING"
                                if pgrep -f "$JBOSS_PSTRING" > /dev/null; then
                                        if [ $lapse_sec -ge $JBOSS_KILL_TIMEOUT 
]; then
                                                break
                                        fi
                                else
                                        break
                                fi
                        else
                                break
                        fi
                done
        fi

        # If the JBoss process hangs, JBoss RA waits $JBOSS_SHUTDOWN_TIMEOUT
        # seconds and tries kill TERM and QUIT for $JBOSS_KILL_TIMEOUT seconds.
        # The stop timeout of RA should be
        # longer than $JBOSS_SHUTDOWN_TIMEOUT + $JBOSS_KILL_TIMEOUT.
        lapse_sec=0
        while pgrep -f "$JBOSS_PSTRING" > /dev/null; do
                sleep 1
                lapse_sec=`expr $lapse_sec + 1`
                ocf_log info "stop_jboss[$JBOSS_NAME]: kill jboss by SIGKILL 
($lapse_sec/@@@)"
                pkill -KILL -f "$JBOSS_PSTRING"
        done
        return $OCF_SUCCESS
}

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

        if isrunning_jboss; then
                echo "JBoss[$JBOSS_NAME] is running."
                return $OCF_SUCCESS
        else
                echo "JBoss process[$JBOSS_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">jboss resource agent</shortdesc>

<parameters>

<parameter name="jboss_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="jboss_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="jboss_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 jboss_kill_timeout.
</longdesc>
<shortdesc>shutdown timeout</shortdesc>
<content type="integer" default="5" />
</parameter>

<parameter name="jboss_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 jboss_shutdown_timeout.
</longdesc>
<shortdesc>stop by signal timeout</shortdesc>
<content type="integer" default="10" />
</parameter>

<parameter name="jboss_user" unique="0" required="0">
<longdesc lang="en">
A user name to start a resource.
</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="http://127.0.0.1:8080"; />
</parameter>

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

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

<parameter name="jboss_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="java -Dprogram.name=run.sh" />
</parameter>

<parameter name="jboss_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="-c default -l lpg4j" />
</parameter>

<parameter name="jboss_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>

</parameters>

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

validate_all_jboss()
{
        ocf_log info "validate_all_jboss[$JBOSS_NAME]"
        return $OCF_SUCCESS
}

COMMAND=$1
JBOSS_NAME="${OCF_RESKEY_jboss_name-${OCF_RESOURCE_INSTANCE}}"
JBOSS_CONSOLE="${OCF_RESKEY_jboss_console-/var/log/${JBOSS_NAME}.log}"
JBOSS_SHUTDOWN_TIMEOUT="${OCF_RESKEY_jboss_shutdown_timeout-5}"
JBOSS_KILL_TIMEOUT="${OCF_RESKEY_jboss_kill_timeout-10}"
RESOURCE_JBOSS_USER="${OCF_RESKEY_jboss_user-root}"
RESOURCE_STATUSURL="${OCF_RESKEY_statusurl-http://127.0.0.1:8080}";
JBOSS_PSTRING="${OCF_RESKEY_jboss_pstring-java -Dprogram.name=run.sh}"
JBOSS_RUN_OPTS="${OCF_RESKEY_jboss_run_opts--c default -l lpg4j}"
JBOSS_SHUTDOWN_OPTS="${OCF_RESKEY_jboss_shutdown_opts--s 127.0.0.1:1099}"

# 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}"
JBOSS_HOME="${OCF_RESKEY_jboss_home}"

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;;
                meta-data)      metadata_jboss;;
        esac
        ocf_log err "JAVA_HOME or JBOSS_HOME does not exist."
        exit $OCF_ERR_INSTALLED
fi

export JAVA_HOME 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;;
                meta-data)      metadata_jboss;;
        esac
        ocf_log err "java command does not exist."
        exit $OCF_ERR_INSTALLED
fi

case "$COMMAND" in
        start)
                #ocf_log debug  "[$JBOSS_NAME] Enter jboss start"
                start_jboss
                func_status=$?
                #ocf_log debug  "[$JBOSS_NAME] Leave jboss start $func_status"
                exit $func_status
                ;;
        stop)
                #ocf_log debug  "[$JBOSS_NAME] Enter jboss stop"
                stop_jboss
                func_status=$?
                #ocf_log debug  "[$JBOSS_NAME] Leave jboss stop $func_status"
                exit $func_status
                ;;
        status)
                status_jboss
                exit $?
                ;;
        monitor)
                monitor_jboss
                func_status=$?
                exit $func_status
                ;;
        # move meta-data above, so that it never fails
        meta-data)
                metadata_jboss
                exit $?
                ;;
        validate-all)
                validate_all_jboss
                exit $?
                ;;
        *)
                usage
                ;;
esac

_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/

Reply via email to