summaryrefslogtreecommitdiffstats
path: root/rgmanager/src/resources/utils/member_util.sh.in
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:52:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 07:52:36 +0000
commit7de03e4e519705301265c0415b3c0af85263a7ac (patch)
tree29d819c5227e3619d18a67d2a5dde963b3229dbe /rgmanager/src/resources/utils/member_util.sh.in
parentInitial commit. (diff)
downloadresource-agents-7de03e4e519705301265c0415b3c0af85263a7ac.tar.xz
resource-agents-7de03e4e519705301265c0415b3c0af85263a7ac.zip
Adding upstream version 1:4.13.0.upstream/1%4.13.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'rgmanager/src/resources/utils/member_util.sh.in')
-rw-r--r--rgmanager/src/resources/utils/member_util.sh.in116
1 files changed, 116 insertions, 0 deletions
diff --git a/rgmanager/src/resources/utils/member_util.sh.in b/rgmanager/src/resources/utils/member_util.sh.in
new file mode 100644
index 0000000..0dab7b7
--- /dev/null
+++ b/rgmanager/src/resources/utils/member_util.sh.in
@@ -0,0 +1,116 @@
+#!@BASH_SHELL@
+#
+# Copyright (C) 1997-2003 Sistina Software, Inc. All rights reserved.
+# Copyright (C) 2004-2011 Red Hat, Inc. All rights reserved.
+#
+# 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+#
+
+#
+# Use corosync-quorumtool to figure out if the specified node is a member
+# of the cluster. Returns 1 if not a member, and
+# 0 if the node is happily running.
+#
+# Tested on RHEL6 and F17 Note that the old version of this function utilized
+# clustat, which had introspection in to the configuration.
+# If a node was not found, the old version would return '2', but the only
+# consumer of this function never cared about that value.
+#
+is_node_member_clustat()
+{
+ local node="$1"
+ local output_list
+
+ # Still having a tag while (a) online but (b) not running pacemaker
+ # (e.g. crm_node) or rgmanager not considered adequate for things like
+ # the LVM agent - so we use corosync-quorumtool instead. The function
+ # name really should be changed.
+ #
+ # corosync 1.4.1 output looks like:
+ #
+ # # corosync-quorumtool -l
+ # Nodeid Name
+ # 1 rhel6-1
+ # 2 rhel6-2
+ #
+ # corosync 2.0.1 output looks like:
+ # # corosync-quorumtool -l
+ #
+ # Membership information
+ # ----------------------
+ # Nodeid Votes Name
+ # 1 1 rhel7-1.priv.redhat.com
+ # 2 1 rhel7-2.priv.redhat.com
+ #
+
+ output_list=$(corosync-quorumtool -l | grep -v "^Nodeid")
+
+ # first try searching for the node in the output as both a FQDN or shortname
+ echo "$output_list" | grep -i -e " $node\$" -e " $node\..*\$" &> /dev/null && return 0
+
+ # if the node was not found in the quorum list, try any known aliases found in /etc/hosts
+ for alias in $(cat /etc/hosts | grep -e "\s$node\s" -e "\s$node\$" | tail -n 1 | sed 's/\t/ /g' | cut -f2- -d " ");
+ do
+ echo "$output_list" | grep -i -e " $alias\$" &> /dev/null && return 0
+ done
+
+ return 1
+}
+
+
+#
+# Print the local node name to stdout
+# Returns 0 if could be found, 1 if not
+# Tested on RHEL6 (cman) and Fedora 17 (corosync/pacemaker)
+#
+local_node_name()
+{
+ local node nid localid
+
+ if which magma_tool &> /dev/null; then
+ # Use magma_tool, if available.
+ line=$(magma_tool localname | grep "^Local")
+
+ if [ -n "$line" ]; then
+ echo ${line/* = /}
+ return 0
+ fi
+ fi
+
+ if which cman_tool &> /dev/null; then
+ # Use cman_tool
+
+ line=$(cman_tool status | grep -i "Node name: $1")
+ [ -n "$line" ] || return 1
+ echo ${line/*name: /}
+ return 0
+ fi
+
+ if ! which crm_node &> /dev/null; then
+ # no crm_node? :(
+ return 2
+ fi
+
+ localid=$(crm_node -i)
+ while read nid node; do
+ if [ "$nid" = "$localid" ]; then
+ echo $node
+ return 0
+ fi
+ done < <(crm_node -l)
+
+ return 1
+}
+