Page Menu
Home
ClusterLabs Projects
Search
Configure Global Search
Log In
Files
F3686843
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
32 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/heartbeat/apache b/heartbeat/apache
index bc891ed86..b249a46c7 100755
--- a/heartbeat/apache
+++ b/heartbeat/apache
@@ -1,747 +1,744 @@
#!/bin/sh
#
# High-Availability Apache/IBMhttp control script
#
# apache (aka IBMhttpd)
#
# Description: starts/stops apache web servers.
#
# Author: Alan Robertson
# Sun Jiang Dong
#
# Support: users@clusterlabs.org
#
# License: GNU General Public License (GPL)
#
# Copyright: (C) 2002-2005 International Business Machines
#
#
# An example usage in /etc/ha.d/haresources:
# node1 10.0.0.170 apache::/opt/IBMHTTPServer/conf/httpd.conf
# node1 10.0.0.170 IBMhttpd
#
# Our parsing of the Apache config files is very rudimentary.
# It'll work with lots of different configurations - but not every
# possible configuration.
#
# Patches are being accepted ;-)
#
# OCF parameters:
# OCF_RESKEY_configfile
# OCF_RESKEY_httpd
# OCF_RESKEY_port
# OCF_RESKEY_statusurl
# OCF_RESKEY_options
# OCF_RESKEY_testregex
# OCF_RESKEY_client
# OCF_RESKEY_testurl
# OCF_RESKEY_testregex10
# OCF_RESKEY_testconffile
# OCF_RESKEY_testname
# OCF_RESKEY_envfiles
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
. ${OCF_FUNCTIONS_DIR}/apache-conf.sh
. ${OCF_FUNCTIONS_DIR}/http-mon.sh
HA_VARRUNDIR=${HA_VARRUN}
# Parameter defaults
OCF_RESKEY_httpd_default="/usr/sbin/httpd"
OCF_RESKEY_envfiles_default="/etc/apache2/envvars"
OCF_RESKEY_use_ipv6_default="false"
#######################################################################
#
# Configuration options - usually you don't need to change these
#
#######################################################################
#
IBMHTTPD=/opt/IBMHTTPServer/bin/httpd
HTTPDLIST="/sbin/httpd2 /usr/sbin/httpd2 /usr/sbin/apache2 /sbin/httpd /usr/sbin/httpd /usr/sbin/apache $IBMHTTPD"
MPM=/usr/share/apache2/find_mpm
if [ -x $MPM ]; then
HTTPDLIST="$HTTPDLIST `$MPM 2>/dev/null`"
fi
LOCALHOST="http://localhost"
HTTPDOPTS="-DSTATUS"
DEFAULT_IBMCONFIG=/opt/IBMHTTPServer/conf/httpd.conf
DEFAULT_SUSECONFIG="/etc/apache2/httpd.conf"
DEFAULT_RHELCONFIG="/etc/httpd/conf/httpd.conf"
DEFAULT_DEBIANCONFIG="/etc/apache2/apache2.conf"
#
# You can also set
# HTTPD
# PORT
# STATUSURL
# CONFIGFILE
# in this section if what we're doing doesn't work for you...
#
# End of Configuration options
#######################################################################
CMD=`basename $0`
# The config-file-pathname is the pathname to the configuration
# file for this web server. Various appropriate defaults are
# assumed if no config file is specified. If this command is
# invoked as *IBM*, then the default config file name is
# $DEFAULT_IBMCONFIG, otherwise the default config file
# will be either $DEFAULT_RHELCONFIG or $DEFAULT_SUSECONFIG depending
# on which is detected.
usage() {
cat <<-END
usage: $0 action
action:
start start the web server
stop stop the web server
status return the status of web server, run or down
monitor return TRUE if the web server appears to be working.
For this to be supported you must configure mod_status
and give it a server-status URL. You have to have
installed either curl or wget for this to work.
meta-data show meta data message
validate-all validate the instance parameters
END
}
get_pid() {
if [ -f $PidFile ]; then
cat $PidFile
else
false
fi
}
#
# return TRUE if a process with given PID is running
#
ProcessRunning() {
local pid=$1
# Use /proc if it looks like it's here...
if [ -d /proc -a -d /proc/1 ]; then
[ -d /proc/$pid ]
else
# This assumes we're running as root...
kill -s 0 "$pid" >/dev/null 2>&1
fi
}
silent_status() {
local pid
local rc=$OCF_ERR_GENERIC
local retries=0
# Set a retry when apache's Graceful restart is applied and the pid file can not be acquired.
if [ "$__OCF_ACTION" = "monitor" ] && ! ocf_is_probe; then
retries=5
fi
while true; do
pid=`get_pid`
if [ -n "$pid" ]; then
ProcessRunning $pid
rc=$?
break
fi
: No pid file
if [ $retries -le 0 ]; then
break
fi
sleep 1
retries=`expr $retries - 1`
done
return $rc
}
# May be useful to add other distros in future
validate_default_config() {
- case "$( get_release_id )" in
- *SUSE)
- validate_default_suse_config
- ;;
- Debian)
- validate_default_debian_config
- ;;
- *)
- return 0
- esac
+ if is_suse_based; then
+ validate_default_suse_config
+ elif is_debian_based; then
+ validate_default_debian_config
+ else
+ return 0
+ fi
}
# When using the default /etc/apache2/httpd.conf on SUSE, the file
# /etc/apache2/sysconfig.d/include.conf is required to be present,
# but this is only generated if you run the apache init script
# (with contents derived from /etc/sysconfig/apache2). So, here,
# if we're using the default system config file and it requires
# that include, we run "/etc/init.d/apache2 configtest" to ensure
# the relevant config is generated and valid. We're also taking
# this opportunity to enable mod_status if it's not present.
validate_default_suse_config() {
if [ "$CONFIGFILE" = "$DEFAULT_SUSECONFIG" ] && \
grep -Eq '^Include[[:space:]]+/etc/apache2/sysconfig.d/include.conf' "$CONFIGFILE"
then
[ -x "/usr/sbin/a2enmod" ] && ocf_run -q /usr/sbin/a2enmod status
# init script style, for crusty old SUSE
if [ -x "/etc/init.d/apache2" ]; then
ocf_run -q /etc/init.d/apache2 configtest || return 1
# systemd style, for shiny new SUSE
elif [ -x "/usr/sbin/start_apache2" ]; then
ocf_run -q /usr/sbin/start_apache2 -t || return 1
fi
fi
# mod_status: some existing users might don't want to use mod_status, check if present in configuration
if [ "$CONFIGFILE" = "$DEFAULT_SUSECONFIG" ] && \
grep -Eq '^Include[[:space:]]+/etc/apache2/mod_status.conf' "$CONFIGFILE"
then
# load module only if module exists
apache_mod_status="/usr/lib64/apache2-prefork/mod_status.so"
if [ -e $apache_mod_status ]; then
LOAD_STATUS_MODULE="LoadModule status_module $apache_mod_status"
fi
fi
return 0
}
# Debian's Default configuration uses a lock directory /var/lock/apache2
# which is only generated using the lsb init script issues configtest. To
# ensure these default directories are present it's useful to run a configtest
# prior to the resource startup which will create the needed directories
#
# To support multiple apache instances the debian scripts and configs
# obey apache2/envvars. (copy /etc/apache2 -> /etc/apache2-instance)
# adjust (SUFFIX) envvars and set OCF_RESKEY_envfiles
validate_default_debian_config() {
if find /etc/apache2* -name apache2.conf | grep -q "$CONFIGFILE"
then
export APACHE_CONFDIR=$(dirname $CONFIGFILE)
[ -x "/usr/sbin/a2enmod" ] && ocf_run -q /usr/sbin/a2enmod status
ocf_run -q /usr/sbin/apache2ctl configtest || return 1
fi
return 0
}
apache_start() {
if
silent_status
then
ocf_log info "$CMD already running (pid `get_pid`)"
return $OCF_SUCCESS
fi
validate_default_config || return $OCF_ERR_CONFIGURED
if [ -z $PIDFILE_DIRECTIVE ]; then
if [ -z "$LOAD_STATUS_MODULE" ]; then
ocf_run $HTTPD $HTTPDOPTS $OPTIONS -f $CONFIGFILE
else
ocf_run $HTTPD -C "$LOAD_STATUS_MODULE" $HTTPDOPTS $OPTIONS -f $CONFIGFILE
fi
else
if [ -z "$LOAD_STATUS_MODULE" ]; then
ocf_run $HTTPD $HTTPDOPTS $OPTIONS -f $CONFIGFILE -c "PidFile $PidFile"
else
ocf_run $HTTPD $HTTPDOPTS -C "$LOAD_STATUS_MODULE" $OPTIONS -f $CONFIGFILE -c "PidFile $PidFile"
fi
fi
tries=0
while : # wait until the user set timeout
do
apache_monitor
ec=$?
if [ $ec -eq $OCF_NOT_RUNNING ]
then
tries=`expr $tries + 1`
ocf_log info "waiting for apache $CONFIGFILE to come up"
sleep 1
else
break
fi
done
if [ $ec -ne 0 ] && silent_status; then
apache_stop
fi
return $ec
}
signal_children()
{
for sig in SIGTERM SIGHUP SIGKILL ; do
if pgrep -f $HTTPD.*$CONFIGFILE >/dev/null ; then
pkill -$sig -f $HTTPD.*$CONFIGFILE >/dev/null
ocf_log info "signal $sig sent to apache children"
sleep 1
else
break
fi
done
}
graceful_stop()
{
local tries=10
local pid=$1
# Try graceful stop for half timeout period if timeout period is present
if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then
tries=$((($OCF_RESKEY_CRM_meta_timeout/1000) / 2))
fi
ocf_log info "Attempting graceful stop of apache PID $pid"
kill -WINCH $pid >/dev/null
while
ProcessRunning $pid &&
[ $tries -gt 0 ]
do
sleep 1
tries=`expr $tries - 1`
done
if [ $tries -eq 0 ]; then
# graceful stop didn't work, process still up.
return 1
fi
return 0
}
kill_stop()
{
local tries=0
local pid=$1
ocf_log info "Killing apache PID $pid"
if ProcessRunning $pid; then
kill $pid >/dev/null
while
[ $tries -lt 10 ]
do
if ProcessRunning $pid; then
tries=`expr $tries + 1`
sleep 1
else
break
fi
done
fi
}
apache_stop() {
local ret=$OCF_SUCCESS
local pid
if ! silent_status; then
ocf_log info "$CMD is not running."
signal_children
return $ret
fi
pid=`get_pid`
graceful_stop $pid
if [ $? -ne 0 ]; then
kill_stop $pid
fi
signal_children
if ProcessRunning $pid; then
ocf_exit_reason "$CMD still running ($pid). Killing pid failed."
ret=$OCF_ERR_GENERIC
fi
if [ $ret -eq 0 ]; then
ocf_log info "$CMD stopped."
fi
return $ret
}
apache_monitor_10() {
if [ -f "$TESTCONFFILE" ] && [ -r "$TESTCONFFILE" ]; then
readtestconf < $TESTCONFFILE
else
test_url="$TESTURL"
test_regex="$TESTREGEX10"
fi
whattorun=`gethttpclient`
fixtesturl
is_testconf_sane ||
return $OCF_ERR_CONFIGURED
if $whattorun "$test_url" | grep -Ei "$test_regex" > /dev/null
then
return $OCF_SUCCESS
else
if ! ocf_is_probe; then
ocf_exit_reason "Failed to access httpd status page."
fi
return $OCF_ERR_GENERIC
fi
}
# If the user has not provided any basic monitoring
# information, allow the agent to verify the server is
# healthy and capable of processing requests by requesting
# the http header of website's index
attempt_index_monitor_request() {
local indexpage=""
if [ -n "$OCF_RESKEY_testregex" ]; then
return 1;
fi
if [ -n "$OCF_RESKEY_testregex10" ]; then
return 1;
fi
if [ -n "$OCF_RESKEY_testurl" ]; then
return 1;
fi
if [ -n "$OCF_RESKEY_statusurl" ]; then
return 1;
fi
if [ -n "$OCF_RESKEY_testconffile" ]; then
return 1;
fi
indexpage=$(buildlocalurl)
request_url_header $indexpage
if [ $? -ne 0 ]; then
return $OCF_ERR_GENERIC
fi
ocf_log debug "Successfully retrieved http header at $indexpage"
return 0
}
apache_monitor_basic() {
if ${ourhttpclient}_func "$STATUSURL" | grep -Ei "$TESTREGEX" > /dev/null
then
return $OCF_SUCCESS
fi
attempt_index_monitor_request
if [ $? -eq 0 ]; then
return $OCF_SUCCESS
fi
if ! ocf_is_probe; then
ocf_exit_reason "Failed to access httpd status page."
fi
return $OCF_ERR_GENERIC
}
apache_monitor() {
silent_status
if [ $? -ne 0 ]; then
ocf_log info "$CMD not running"
return $OCF_NOT_RUNNING
fi
ourhttpclient=`findhttpclient` # we'll need one
if [ -z "$ourhttpclient" ]; then
ocf_exit_reason "could not find a http client; make sure that either wget or curl is available"
return $OCF_ERR_INSTALLED
fi
case `ocf_check_level 10` in
0) apache_monitor_basic;;
10) apache_monitor_10;;
esac
}
detect_default_config()
{
if [ -f $DEFAULT_SUSECONFIG ]; then
echo $DEFAULT_SUSECONFIG
elif [ -f $DEFAULT_DEBIANCONFIG ]; then
echo $DEFAULT_DEBIANCONFIG
else
echo $DEFAULT_RHELCONFIG
fi
}
apache_meta_data(){
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.
This resource agent operates both version 1.x and version 2.x Apache
servers.
The start operation ends with a loop in which monitor is
repeatedly called to make sure that the server started and that
it is operational. Hence, if the monitor operation does not
succeed within the start operation timeout, the apache resource
will end with an error status.
The monitor operation by default loads the server status page
which depends on the mod_status module and the corresponding
configuration file (usually /etc/apache2/mod_status.conf).
Make sure that the server status page works and that the access
is allowed *only* from localhost (address 127.0.0.1).
See the statusurl and testregex attributes for more details.
See also http://httpd.apache.org/
</longdesc>
<shortdesc lang="en">Manages an Apache Web server instance</shortdesc>
<parameters>
<parameter name="configfile" required="0" 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="$(detect_default_config)" />
</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="${OCF_RESKEY_httpd_default}" />
</parameter>
<parameter name="port" >
<longdesc lang="en">
A port number that we can probe for status information
using the statusurl.
This will default to the port number found in the
configuration file, or 80, if none can be found
in the configuration file.
</longdesc>
<shortdesc lang="en">httpd port</shortdesc>
<content type="integer" />
</parameter>
<parameter name="statusurl">
<longdesc lang="en">
The URL to monitor (the apache server status page by default).
If left unspecified, it will be inferred from
the apache configuration file.
If you set this, make sure that it succeeds *only* from the
localhost (127.0.0.1). Otherwise, it may happen that the cluster
complains about the resource being active on multiple nodes.
</longdesc>
<shortdesc lang="en">url name</shortdesc>
<content type="string" />
</parameter>
<parameter name="testregex">
<longdesc lang="en">
Regular expression to match in the output of statusurl.
Case insensitive.
</longdesc>
<shortdesc lang="en">monitor regular expression</shortdesc>
<content type="string" default="exists, but impossible to show in a human readable format (try grep testregex)"/>
</parameter>
<parameter name="client">
<longdesc lang="en">
Client to use to query to Apache. If not specified, the RA will
try to find one on the system. Currently, wget and curl are
supported. For example, you can set this parameter to "curl" if
you prefer that to wget.
</longdesc>
<shortdesc lang="en">http client</shortdesc>
<content type="string" default=""/>
</parameter>
<parameter name="testurl">
<longdesc lang="en">
URL to test. If it does not start with "http", then it's
considered to be relative to the Listen address.
</longdesc>
<shortdesc lang="en">test url</shortdesc>
<content type="string" />
</parameter>
<parameter name="testregex10">
<longdesc lang="en">
Regular expression to match in the output of testurl.
Case insensitive.
</longdesc>
<shortdesc lang="en">extended monitor regular expression</shortdesc>
<content type="string" />
</parameter>
<parameter name="testconffile">
<longdesc lang="en">
A file which contains test configuration. Could be useful if
you have to check more than one web application or in case sensitive
info should be passed as arguments (passwords). Furthermore,
using a config file is the only way to specify certain
parameters.
Please see README.webapps for examples and file description.
</longdesc>
<shortdesc lang="en">test configuration file</shortdesc>
<content type="string" />
</parameter>
<parameter name="testname">
<longdesc lang="en">
Name of the test within the test configuration file.
</longdesc>
<shortdesc lang="en">test name</shortdesc>
<content type="string" />
</parameter>
<parameter name="options">
<longdesc lang="en">
Extra options to apply when starting apache. See man httpd(8).
</longdesc>
<shortdesc lang="en">command line options</shortdesc>
<content type="string" />
</parameter>
<parameter name="envfiles">
<longdesc lang="en">
Files (one or more) which contain extra environment variables.
If you want to prevent script from reading the default file, set
this parameter to empty string.
</longdesc>
<shortdesc lang="en">environment settings files</shortdesc>
<content type="string" default="${OCF_RESKEY_envfiles_default}"/>
</parameter>
<parameter name="use_ipv6">
<longdesc lang="en">
We will try to detect if the URL (for monitor) is IPv6, but if
that doesn't work set this to true to enforce IPv6.
</longdesc>
<shortdesc lang="en">use ipv6 with http clients</shortdesc>
<content type="boolean" default="${OCF_RESKEY_use_ipv6_default}"/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="40s" />
<action name="stop" timeout="60s" />
<action name="status" timeout="30s" />
<action name="monitor" depth="0" timeout="20s" interval="10s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="5s" />
</actions>
</resource-agent>
END
return $OCF_SUCCESS
}
apache_validate_all() {
if [ -z "$HTTPD" ]; then
ocf_exit_reason "apache httpd program not found"
return $OCF_ERR_INSTALLED
fi
if [ ! -x "$HTTPD" ]; then
ocf_exit_reason "HTTPD $HTTPD not found or is not an executable!"
return $OCF_ERR_INSTALLED
fi
if [ ! -f $CONFIGFILE ]; then
ocf_exit_reason "Configuration file $CONFIGFILE not found!"
return $OCF_ERR_INSTALLED
fi
# validate testconffile/testurl before apache_monitor_10()
if [ -n "$TESTCONFFILE" ]; then
if [ ! -f "$TESTCONFFILE" ] || [ ! -r "$TESTCONFFILE" ]; then
ocf_exit_reason "Configuration file $TESTCONFFILE not found, or not readable."
return $OCF_ERR_INSTALLED
fi
else
if [ -n "$TESTURL" ]; then
# remove leading or trailing spaces/tabs
local temp=$(printf "$TESTURL" | sed -e 's/^[ \t]*//g' -e 's/[ \t]*$//g')
if [ -z "$temp" ]; then
ocf_exit_reason "testurl: \"$TESTURL\" seems to be an empty string?"
return $OCF_ERR_CONFIGURED
fi
fi
# FIXME: validate TESTREGEX10 will be needed if empty regex is not allow.
fi
ocf_mkstatedir root 755 `dirname $PidFile` || return $OCF_ERR_INSTALLED
return $OCF_SUCCESS
}
find_httpd_prog() {
case $0 in
*IBM*)
HTTPD=$IBMHTTPD
DefaultConfig=$DEFAULT_IBMCONFIG;;
*)
HTTPD=
for h in $HTTPDLIST
do
if [ -f $h -a -x $h ]; then
HTTPD=$h
break
fi
done
# Let the user know that the $HTTPD used is not the one (s)he specified via $OCF_RESKEY_httpd
if [ "X$OCF_RESKEY_httpd" != X -a "X$HTTPD" != X ]; then
ocf_log info "Using $HTTPD as HTTPD"
fi
DefaultConfig=$(detect_default_config)
;;
esac
}
apache_getconfig() {
# these variables are global
HTTPD="$OCF_RESKEY_httpd"
PORT="$OCF_RESKEY_port"
STATUSURL="$OCF_RESKEY_statusurl"
CONFIGFILE="$OCF_RESKEY_configfile"
OPTIONS="$OCF_RESKEY_options"
CLIENT=${OCF_RESKEY_client}
TESTREGEX=${OCF_RESKEY_testregex:-'</ *html *>'}
TESTURL="$OCF_RESKEY_testurl"
TESTREGEX10=${OCF_RESKEY_testregex10}
TESTCONFFILE="$OCF_RESKEY_testconffile"
TESTNAME="$OCF_RESKEY_testname"
: ${OCF_RESKEY_envfiles=${OCF_RESKEY_envfiles_default}}
source_envfiles $OCF_RESKEY_envfiles
if [ "X$HTTPD" = X -o ! -f "$HTTPD" -o ! -x "$HTTPD" ]; then
find_httpd_prog
fi
CONFIGFILE=${CONFIGFILE:-$DefaultConfig}
if [ -n "$HTTPD" ]; then
httpd_basename=`basename $HTTPD`
case $httpd_basename in
*-*) httpd_basename=`echo "$httpd_basename" | sed -e 's%\-.*%%'`;;
esac
fi
GetParams $CONFIGFILE
}
OCF_REQUIRED_PARAMS=""
OCF_REQUIRED_BINARIES=""
ocf_rarun $*
diff --git a/heartbeat/azure-lb b/heartbeat/azure-lb
index 05755d778..65a12235b 100755
--- a/heartbeat/azure-lb
+++ b/heartbeat/azure-lb
@@ -1,223 +1,223 @@
#!/bin/sh
#
# License: GNU General Public License (GPL)
# (c) 2017 O. Albrigtsen
# and Linux-HA contributors
#
# -----------------------------------------------------------------------------
# O C F R E S O U R C E S C R I P T S P E C I F I C A T I O N
# -----------------------------------------------------------------------------
#
# NAME
# azure-lb : OCF resource agent script for Azure Load Balancer
#
# Initialization:
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
# Defaults
-OCF_RESKEY_nc_default="/usr/bin/nc"
-case "$( get_release_id )" in
- *SUSE)
- OCF_RESKEY_nc_default="/usr/bin/socat"
- ;;
-esac
+if is_suse_based; then
+ OCF_RESKEY_nc_default="/usr/bin/socat"
+else
+ OCF_RESKEY_nc_default="/usr/bin/nc"
+fi
+
OCF_RESKEY_port_default="61000"
: ${OCF_RESKEY_nc=${OCF_RESKEY_nc_default}}
: ${OCF_RESKEY_port=${OCF_RESKEY_port_default}}
process="$OCF_RESOURCE_INSTANCE"
pidfile="/var/run/$OCF_RESOURCE_INSTANCE.pid"
lb_usage() {
cat <<END
usage: $0 (start|stop|validate-all|meta-data|help|usage|monitor)
$0 manages service that answers Azure Load Balancer health probe requests as a OCF HA resource.
The 'start' operation starts the instance.
The 'stop' operation stops the instance.
The 'monitor' operation reports whether the instance seems to be working
The 'validate-all' operation reports whether the parameters are valid
END
}
lb_metadata() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="azure-lb">
<version>1.0</version>
<longdesc lang="en">
Resource agent to answer Azure Load Balancer health probe requests
</longdesc>
<shortdesc lang="en">Answers Azure Load Balancer health probe requests</shortdesc>
<parameters>
<parameter name="nc">
<longdesc lang="en">
The full path of the used binary. This can be nc or socat path.
The default is /usr/bin/nc and /usr/bin/socat for SUSE distributions.
</longdesc>
<shortdesc lang="en">Full path of the used binary (nc or socat are allowed)</shortdesc>
<content type="string" default="${OCF_RESKEY_nc_default}"/>
</parameter>
<parameter name="port">
<longdesc lang="en">
Port to listen to.
</longdesc>
<shortdesc lang="en">Listen to port</shortdesc>
<content type="string" default="${OCF_RESKEY_port_default}"/>
</parameter>
</parameters>
<actions>
<action name="start" timeout="20s" />
<action name="stop" timeout="20s" />
<action name="monitor" depth="0" timeout="20s" interval="10s" />
<action name="meta-data" timeout="5s" />
<action name="validate-all" timeout="5s" />
</actions>
</resource-agent>
END
exit 0
}
getpid() {
grep -o '[0-9]*' $1
}
lb_monitor() {
if test -f "$pidfile"; then
if pid=`getpid $pidfile` && [ "$pid" ] && kill -s 0 $pid; then
return $OCF_SUCCESS
else
# pidfile w/o process means the process died
return $OCF_ERR_GENERIC
fi
else
return $OCF_NOT_RUNNING
fi
}
lb_start() {
cmd="$OCF_RESKEY_nc -l -k $OCF_RESKEY_port"
if [ $( basename $OCF_RESKEY_nc ) = 'socat' ]; then
#socat has different parameters
cmd="$OCF_RESKEY_nc -U TCP-LISTEN:$OCF_RESKEY_port,backlog=10,fork,reuseaddr /dev/null"
fi
if ! lb_monitor; then
ocf_log debug "Starting $process: $cmd"
# Execute the command as created above
$cmd &
echo $! > $pidfile
if lb_monitor; then
ocf_log debug "$process: $cmd started successfully, calling monitor"
lb_monitor
return $?
else
ocf_log err "$process: $cmd could not be started"
return $OCF_ERR_GENERIC
fi
else
# If already running, consider start successful
ocf_log debug "$process: $cmd is already running"
return $OCF_SUCCESS
fi
}
lb_stop() {
local rc=$OCF_SUCCESS
if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then
# Allow 2/3 of the action timeout for the orderly shutdown
# (The origin unit is ms, hence the conversion)
stop_timeout=$((OCF_RESKEY_CRM_meta_timeout/1500))
else
stop_timeout=10
fi
if lb_monitor; then
pid=`getpid $pidfile`
kill $pid
i=0
while [ $i -lt $stop_timeout ]; do
if ! lb_monitor; then
rm -f $pidfile
return $OCF_SUCCESS
fi
sleep 1
i=$((i+1))
done
ocf_log warn "Stop with SIGTERM failed/timed out, now sending SIGKILL."
kill -s 9 $pid
while :; do
if ! lb_monitor; then
ocf_log warn "SIGKILL did the job."
rc=$OCF_SUCCESS
break
fi
ocf_log info "The job still hasn't stopped yet. Waiting..."
sleep 1
done
fi
rm -f $pidfile
return $rc
}
lb_validate() {
check_binary "$OCF_RESKEY_nc"
if ! ocf_is_decimal "$OCF_RESKEY_port"; then
ocf_exit_reason "$OCF_RESKEY_port is not a valid port"
exit $OCF_ERR_CONFIGURED
fi
return $OCF_SUCCESS
}
###############################################################################
#
# MAIN
#
###############################################################################
case $__OCF_ACTION in
meta-data)
lb_metadata
exit $OCF_SUCCESS
;;
usage|help)
lb_usage
exit $OCF_SUCCESS
;;
esac
if ! ocf_is_root; then
ocf_log err "You must be root for $__OCF_ACTION operation."
exit $OCF_ERR_PERM
fi
case $__OCF_ACTION in
start)
lb_validate
lb_start;;
stop)
lb_stop;;
monitor)
lb_monitor;;
validate-all)
lb_validate;;
*)
echo $USAGE
exit $OCF_ERR_UNIMPLEMENTED
;;
esac
exit $?
diff --git a/heartbeat/ocf-distro b/heartbeat/ocf-distro
index f69910c98..9ccb6731a 100644
--- a/heartbeat/ocf-distro
+++ b/heartbeat/ocf-distro
@@ -1,47 +1,213 @@
#
# This is OCF Linux distribution query support
#
# Currently needed for the nfsserver RA which has some already
# released RH specific stuff (/etc/sysconfig/nfs editing)
+#
+# These functions are intended to be POSIX-compliant for portability.
#
+# systemd-based systems should all have an os-release file.
+_ETC_OS_RELEASE_FILE="/etc/os-release"
+_USR_OS_RELEASE_FILE="/usr/lib/os-release"
+
+# Legacy distro-specific files
_DEBIAN_VERSION_FILE="/etc/debian_version"
_REDHAT_RELEASE_FILE="/etc/redhat-release"
_SUSE_RELEASE_FILE="/etc/SuSE-release"
-_RELEASE_FILES="/etc/*-release"
-_REDHAT_BASED_DISTROS_RE='red *hat|fedora|centos|scientific linux'
-get_release_id() {
- if which lsb_release >/dev/null 2>&1; then
- lsb_release -si
- elif [ -e $_DEBIAN_VERSION_FILE ]; then
- echo Debian
- elif [ -e $_SUSE_RELEASE_FILE ]; then
- echo SUSE
- elif [ -e $_REDHAT_RELEASE_FILE ]; then
- echo Redhat
- else # FIXME not exactly the id here, but will do for our purpose
- cat $_RELEASE_FILES 2>/dev/null
+_DEBIAN_BASED_DISTROS_RE="debian|ubuntu"
+_REDHAT_BASED_DISTROS_RE="red *hat|rhel|fedora|centos|scientific"
+_SUSE_BASED_DISTROS_RE="sles|suse"
+
+
+# Converts OS release ID to a standard form regardless of source.
+_process_os_release_id() {
+ _os="$1"
+
+ # Convert to lowercase, isolate distro name, remove whitespace
+ _os=$(echo "$_os" \
+ | tr "[:upper:]" "[:lower:]" \
+ | sed -e "s|\(gnu/\)*linux||" -e "s/server//" \
+ -e "s/release.*//" -e "s/[[:digit:]].*//" \
+ -e "s/[[:blank:]]//")
+
+ # Normalize known distros to os-release names
+ case "$_os" in
+ *centos*)
+ _os="centos"
+ ;;
+ *debian*)
+ _os="debian"
+ ;;
+ *fedora*)
+ _os="fedora"
+ ;;
+ *redhat*|*rhel*|*scientific*)
+ _os="rhel"
+ ;;
+ *opensuse*)
+ _os="opensuse"
+ ;;
+ *suseenterprise*)
+ _os="sles"
+ ;;
+ *ubuntu*)
+ _os="ubuntu"
+ ;;
+ esac
+
+ echo "$_os"
+}
+
+# Converts OS version ID to a form that ocf_version_cmp() can handle.
+# Strips any garbage.
+_process_os_version_id() {
+ _ver="$1"
+
+ # Discard everything except the version.
+ # Use ocf_version_cmp() format if present, or bare integer
+ # otherwise.
+ # Append ".0" for integers so that ocf_version_cmp() doesn't
+ # fail.
+ _ver_cmp_fmt="[[:digit:]][[:digit:].-]*[[:digit:]]"
+ _ver=$(echo "$_ver" \
+ | sed -n -e "s/[^[:digit:]]*\(${_ver_cmp_fmt}\).*/\1/p" \
+ -e "s/[^[:digit:]]*\([[:digit:]]*\).*/\1.0/p" \
+ | head -n 1)
+
+ echo "$_ver"
+}
+
+# Gets OS release ID (i.e., distro) or version ID from os-release file.
+# $_ETC_OS_RELEASE_FILE takes precedence over $_USR_OS_RELEASE_FILE.
+_get_val_from_os_release_file() {
+ _key=""
+ _value=""
+ _func=""
+
+ case "$1" in
+ id)
+ _key="ID"
+ _func="_process_os_release_id"
+ ;;
+ version_id)
+ _key="VERSION_ID"
+ _func="_process_os_version_id"
+ ;;
+ esac
+
+ if [ -n "$_key" ]; then
+ if [ -f "$_ETC_OS_RELEASE_FILE" ]; then
+ _value=$(awk -F "=" -v k="$_key" '$1 == k {print $2}' \
+ "$_ETC_OS_RELEASE_FILE" | tr -d \")
+ fi
+
+ if [ -z "$_value" ] && [ -f "$_USR_OS_RELEASE_FILE" ]; then
+ _value=$(awk -F "=" -v k="$_key" '$1 == k {print $2}' \
+ "$_USR_OS_RELEASE_FILE" | tr -d \")
+ fi
fi
+
+ # Ensure the value is in the correct format
+ [ -n "$_func" ] && _value=$("$_func" "$_value")
+
+ echo "$_value"
}
-is_redhat_based() {
- get_release_id | egrep -qsi "$_REDHAT_BASED_DISTROS_RE"
+# Gets OS release ID from lsb_release command or legacy *-release files
+_get_os_from_legacy_source() {
+ _os=""
+
+ if which lsb_release >/dev/null 2>&1; then
+ _os=$(lsb_release -si)
+
+ elif [ -f "$_DEBIAN_VERSION_FILE" ]; then
+ _os="debian"
+
+ elif [ -f "$_REDHAT_RELEASE_FILE" ]; then
+ _os=$(head -n 1 "$_REDHAT_RELEASE_FILE")
+
+ elif [ -f "$_SUSE_RELEASE_FILE" ]; then
+ _os=$(head -n 1 "$_SUSE_RELEASE_FILE")
+
+ else
+ _os=$(uname -s)
+ fi
+
+ _process_os_release_id "$_os"
}
-# get_os_ver() is currently unused
-get_os_ver() {
+# Gets OS version from lsb_release command or legacy *-release files
+_get_version_from_legacy_source() {
+ _ver=""
+
if which lsb_release >/dev/null 2>&1; then
- OS=`lsb_release -si`
- VER=`lsb_release -sr`
- elif [ -f $_DEBIAN_VERSION_FILE ]; then
- OS=Debian
- VER=$(cat $_DEBIAN_VERSION_FILE)
- elif [ -f $_REDHAT_RELEASE_FILE ]; then
- OS=RedHat # redhat or similar
- VER=$(sed "s/.* release \([^ ]\+\).*/\1/" $_REDHAT_RELEASE_FILE)
+ _ver=$(lsb_release -sr)
+
+ elif [ -f "$_DEBIAN_VERSION_FILE" ]; then
+ _ver=$(cat "$_DEBIAN_VERSION_FILE")
+
+ elif [ -f "$_REDHAT_RELEASE_FILE" ]; then
+ _ver=$(head -1 "$_REDHAT_RELEASE_FILE")
+
+ elif [ -f "$_SUSE_RELEASE_FILE" ]; then
+ _ver=$(awk '$1 == "VERSION" {print $3}' "$_SUSE_RELEASE_FILE")
+ _patchlevel=$(awk '$1 == "PATCHLEVEL" {print $3}' \
+ "$_SUSE_RELEASE_FILE")
+
+ [ -n "$_patchlevel" ] && _ver="${_ver}.${_patchlevel}"
+
else
- OS=$(uname -s)
- VER=$(uname -r)
+ _ver=$(uname -r)
fi
+
+ _process_os_version_id "$_ver"
+}
+
+# Prints OS release ID (i.e., distro name)
+get_release_id() {
+ _os=$(_get_val_from_os_release_file id)
+
+ if [ -z "$_os" ]; then
+ _os=$(_get_os_from_legacy_source)
+ fi
+
+ echo "$_os"
+}
+
+# Prints OS version ID
+get_os_version_id() {
+ _ver=$(_get_val_from_os_release_file version_id)
+
+ if [ -z "$_ver" ] || [ "$(get_release_id)" = "debian" ]; then
+ # Debian only includes major release in os-release.
+ # $_DEBIAN_VERSION_FILE has ${major}.${minor}.
+ _ver=$(_get_version_from_legacy_source)
+ fi
+
+ echo "$_ver"
+}
+
+# Returns true if the OS is Debian-based, otherwise false
+is_debian_based() {
+ get_release_id | grep -Eqi "$_DEBIAN_BASED_DISTROS_RE"
+}
+
+# Returns true if the OS is Red Hat-based, otherwise false
+is_redhat_based() {
+ get_release_id | grep -Eqi "$_REDHAT_BASED_DISTROS_RE"
+}
+
+# Returns true if the OS is SUSE-based, otherwise false
+is_suse_based() {
+ get_release_id | grep -Eqi "$_SUSE_BASED_DISTROS_RE"
+}
+
+# Sets global variables OS and VER.
+# get_os_ver() is currently unused upstream; maintained for backwards
+# compatibility.
+get_os_ver() {
+ OS=$(get_release_id)
+ VER=$(get_os_version_id)
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Apr 21, 6:06 PM (22 h, 55 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1665067
Default Alt Text
(32 KB)
Attached To
Mode
rR Resource Agents
Attached
Detach File
Event Timeline
Log In to Comment