Lars Marowsky-Bree schrieb:

> Oh, I totally approve!
> 
> Be our hero, submit a patch ;-) If we meet, pizza is on me!

Well, alright. Who can say no to pizza? :-D

I attached a pre-alpha, untested,
do-not-use-in-production-unless-you-are-a-complete-lunatic version of
what I have in mind. I hacked it together just now in a very short time,
after a stressful day involving a failing mail relay and a very
bureaucratic telephone company, but it should give you a rough idea of
where I'm going with this, and whether you like the general approach.

Scroll past the metadata (which I blatantly copied from the old script)
to get to the action. The idea pretty much is to set some environment
variables and outsource all the real work to apache2ctl, then deal with
its results.

Also, I have one question - the current apache RA has a status command,
which apparently checks whether the process in the pid file is running.
I couldn't find this at http://www.linux-ha.org/OCFResourceAgent , and
it does seem to serve pretty much the same ends as monitor, so I clipped
it for now. Is this a horrible idea because the status command is
absolutely essential for the script to function, or am I within my
rights there?

Regards,

Florian Knauf
#!/bin/sh

# OCF parameters:
#  OCF_RESKEY_configfile
#  OCF_RESKEY_httpd
#  OCF_RESKEY_statusurl

. ${OCF_ROOT}/resource.d/heartbeat/.ocf-shellfuncs
HA_VARRUNDIR=${HA_VARRUN}

COMMAND=$1

[ ! -z "$OCF_RESKEY_configfile" ] && export APACHE_ARGUMENTS="-f 
$OCF_RESKEY_configfile"
[ ! -z "$OCF_RESKEY_httpd"      ] && export APACHE_HTTPD="$OCF_RESKEY_httpd"
[ ! -z "$OCF_RESKEY_statusurl"  ] && export 
APACHE_STATUSURL="$OCF_RESKEY_statusurl"

usage() {
    cat <<EOF
$0 { start | stop | monitor | meta-data | validate-all }
EOF
}

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

<longdesc lang="en">
This is the resource agent for the
Apache web server.
Thie resource agent operates both version 1.x and version 2.x Apache
servers.
See also http://httpd.apache.org/
</longdesc>
<shortdesc lang="en">Apache web server</shortdesc>

<parameters>
<parameter name="configfile" required="1" unique="1">
<longdesc lang="en">
The full pathname of the Apache configuration file.
This file is parsed to provide defaults for various other
resource agent parameters.
</longdesc>
<shortdesc lang="en">configuration file path</shortdesc>
<content type="string" default="/etc/apache2/httpd.conf" />
</parameter>

<parameter name="httpd">
<longdesc lang="en">
The full pathname of the httpd binary (optional).
</longdesc>
<shortdesc lang="en">httpd binary path</shortdesc>
<content type="string" default="/usr/sbin/httpd" />
</parameter>

<parameter name="statusurl">
<longdesc lang="en">
The URL of the apache status module.
If left unspecified, it will be inferred
from the apache configuration file.
</longdesc>
<shortdesc lang="en">url name</shortdesc>
<content type="string" />
</parameter>

</parameters>

<actions>
<action name="start"   timeout="90" />
<action name="stop"    timeout="100" />
<action name="status"  timeout="30" />
<action name="monitor" depth="0"  timeout="20" interval="10" start-delay="1m" />
<action name="meta-data"  timeout="5" />
<action name="validate-all"  timeout="5" />
</actions>
</resource-agent>
END

        exit $OCF_SUCCESS
}

# TODO: Name pending, because this doesn't work well for validate-all and
#       monitor
run_apache2ctl() {
    ACTION="$1"
    EXPECTED="$2"

    # TODO: Find more sensible way to determine OCF_CHECK_LEVEL
    OCF_CHECK_LEVEL=0 monitor_apache
    RESULT=$?

    if [ "$RESULT" == "$EXPECTED" ]; then
        ocf_run apache2ctl "$ACTION"
        RESULT=$?
    fi

    return $RESULT
}

start_apache() {
    run_apache2ctl start $OCF_NOT_RUNNING
}

stop_apache() {
    run_apache2ctl stop $OCF_SUCCESS
}

monitor_apache() {
    # Unfortunately, apache2ctl doesn't return an error code if it can't read
    # the status url. It does, however, write nothing to stdout, so we can do
    # this:
    if [ -z "$(apache2ctl status 2>/dev/null)" ]; then
        return $OCF_SUCCESS
    else
        return $OCF_NOT_RUNNING
    fi

    # is there a "This should never happen, ever!" error code?
    return $OCF_ERR_GENERIC
}

validate_all_apache() {
    ocf_run apache2ctl configtest

    if [ "$?" -eq 0 ]; then
        return $OCF_SUCCESS
    else
        return $OCF_ERR_ARGS
    fi

    return $OCF_ERR_GENERIC
}

case $COMMAND in
  start)        start_apache;;
  stop)         stop_apache;;
  monitor)      monitor_apache;;
  meta-data)    metadata_apache;;
  validate-all) validate_all_apache;;
  *)            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