Blame SOURCES/bz2069270-corosync-qnetd-new-ra.patch

d5211c
From d59a000da2766476538bb82d1889f5c0f3882f9f Mon Sep 17 00:00:00 2001
d5211c
From: Jan Friesse <jfriesse@redhat.com>
d5211c
Date: Wed, 2 Mar 2022 18:43:31 +0100
d5211c
Subject: [PATCH] corosync-qnetd: Add resource agent
d5211c
d5211c
Mostly for better monitor operation using corosync-qnetd-tool. As qnetd
d5211c
is (almost) stateless only directory which has to be copied (once)
d5211c
across the nodes is nss db directory (usually
d5211c
/etc/corosync/qnetd/nssdb).
d5211c
d5211c
Signed-off-by: Jan Friesse <jfriesse@redhat.com>
d5211c
---
d5211c
 doc/man/Makefile.am      |   1 +
d5211c
 heartbeat/Makefile.am    |   1 +
d5211c
 heartbeat/corosync-qnetd | 353 +++++++++++++++++++++++++++++++++++++++
d5211c
 3 files changed, 355 insertions(+)
d5211c
 create mode 100755 heartbeat/corosync-qnetd
d5211c
d5211c
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am
d5211c
index 1093717fe..013aa392d 100644
d5211c
--- a/doc/man/Makefile.am
d5211c
+++ b/doc/man/Makefile.am
d5211c
@@ -127,6 +127,7 @@ man_MANS                = ocf_heartbeat_AoEtarget.7 \
d5211c
                           ocf_heartbeat_azure-lb.7 \
d5211c
                           ocf_heartbeat_clvm.7 \
d5211c
                           ocf_heartbeat_conntrackd.7 \
d5211c
+                          ocf_heartbeat_corosync-qnetd.7 \
d5211c
                           ocf_heartbeat_crypt.7 \
d5211c
                           ocf_heartbeat_db2.7 \
d5211c
                           ocf_heartbeat_dhcpd.7 \
d5211c
diff --git a/heartbeat/Makefile.am b/heartbeat/Makefile.am
d5211c
index 67b400679..38154e2da 100644
d5211c
--- a/heartbeat/Makefile.am
d5211c
+++ b/heartbeat/Makefile.am
d5211c
@@ -101,6 +101,7 @@ ocf_SCRIPTS	      = AoEtarget		\
d5211c
 			azure-lb		\
d5211c
 			clvm			\
d5211c
 			conntrackd		\
d5211c
+			corosync-qnetd		\
d5211c
 			crypt			\
d5211c
 			db2			\
d5211c
 			dhcpd			\
d5211c
diff --git a/heartbeat/corosync-qnetd b/heartbeat/corosync-qnetd
d5211c
new file mode 100755
d5211c
index 000000000..6b9777711
d5211c
--- /dev/null
d5211c
+++ b/heartbeat/corosync-qnetd
d5211c
@@ -0,0 +1,353 @@
d5211c
+#!/bin/sh
d5211c
+#
d5211c
+# Copyright (C) 2022 Red Hat, Inc.  All rights reserved.
d5211c
+#
d5211c
+# Authors: Jan Friesse <jfriesse@redhat.com>
d5211c
+#
d5211c
+# This program is free software; you can redistribute it and/or modify
d5211c
+# it under the terms of version 2 of the GNU General Public License as
d5211c
+# published by the Free Software Foundation.
d5211c
+#
d5211c
+# This program is distributed in the hope that it would be useful, but
d5211c
+# WITHOUT ANY WARRANTY; without even the implied warranty of
d5211c
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
d5211c
+#
d5211c
+# Further, this software is distributed without any warranty that it is
d5211c
+# free of the rightful claim of any third person regarding infringement
d5211c
+# or the like.  Any license provided herein, whether implied or
d5211c
+# otherwise, applies only to this software file.  Patent licenses, if
d5211c
+# any, provided herein do not apply to combinations of this program with
d5211c
+# other software, or any other product whatsoever.
d5211c
+#
d5211c
+# You should have received a copy of the GNU General Public License
d5211c
+# along with this program; if not, write the Free Software Foundation,
d5211c
+# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
d5211c
+#
d5211c
+
d5211c
+# Initialization:
d5211c
+: "${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}"
d5211c
+. "${OCF_FUNCTIONS_DIR}/ocf-shellfuncs"
d5211c
+
d5211c
+# Use runuser if available for SELinux.
d5211c
+if [ -x "/sbin/runuser" ]; then
d5211c
+    SU="runuser"
d5211c
+else
d5211c
+    SU="su"
d5211c
+fi
d5211c
+
d5211c
+# Attempt to detect a default binary
d5211c
+OCF_RESKEY_binary_default=$(which corosync-qnetd 2> /dev/null)
d5211c
+if [ "${OCF_RESKEY_binary_default}" = "" ]; then
d5211c
+    OCF_RESKEY_binary_default="/usr/bin/corosync-qnetd"
d5211c
+fi
d5211c
+
d5211c
+# Defaults
d5211c
+OCF_RESKEY_qnetd_opts_default=""
d5211c
+OCF_RESKEY_qnetd_tool_binary_default="/usr/bin/corosync-qnetd-tool"
d5211c
+OCF_RESKEY_ip_default=""
d5211c
+OCF_RESKEY_port_default=""
d5211c
+OCF_RESKEY_nss_db_dir_default=""
d5211c
+OCF_RESKEY_pid_default="/var/run/corosync-qnetd/corosync-qnetd-${OCF_RESOURCE_INSTANCE}.pid"
d5211c
+OCF_RESKEY_ipc_sock_default="/var/run/corosync-qnetd/corosync-qnetd-${OCF_RESOURCE_INSTANCE}.sock"
d5211c
+OCF_RESKEY_user_default="coroqnetd"
d5211c
+OCF_RESKEY_group_default="${OCF_RESKEY_user_default}"
d5211c
+
d5211c
+: "${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}}"
d5211c
+: "${OCF_RESKEY_qnetd_opts=${OCF_RESKEY_qnetd_opts_default}}"
d5211c
+: "${OCF_RESKEY_qnetd_tool_binary=${OCF_RESKEY_qnetd_tool_binary_default}}"
d5211c
+: "${OCF_RESKEY_ip=${OCF_RESKEY_ip_default}}"
d5211c
+: "${OCF_RESKEY_port=${OCF_RESKEY_port_default}}"
d5211c
+: "${OCF_RESKEY_nss_db_dir=${OCF_RESKEY_nss_db_dir_default}}"
d5211c
+: "${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}}"
d5211c
+: "${OCF_RESKEY_ipc_sock=${OCF_RESKEY_ipc_sock_default}}"
d5211c
+: "${OCF_RESKEY_user=${OCF_RESKEY_user_default}}"
d5211c
+: "${OCF_RESKEY_group=${OCF_RESKEY_group_default}}"
d5211c
+
d5211c
+corosync_qnetd_usage() {
d5211c
+    cat <
d5211c
+usage: $0 {start|stop|status|monitor|validate-all|meta-data}
d5211c
+
d5211c
+Expects to have a fully populated OCF RA-compliant environment set.
d5211c
+END
d5211c
+}
d5211c
+
d5211c
+corosync_qnetd_meta_data() {
d5211c
+        cat <
d5211c
+
d5211c
+
d5211c
+<resource-agent name="corosync-qnetd" version="1.0">
d5211c
+<version>1.0</version>
d5211c
+
d5211c
+<longdesc lang="en">OCF Resource script for corosync-qnetd. It manages a corosync-qnetd
d5211c
+instance as a HA resource. It is required to copy nss db directory (usually /etc/corosync/qnetd/nssdb)
d5211c
+across all nodes (only once - after database is initialized).</longdesc>
d5211c
+<shortdesc lang="en">Corosync QNet daemon resource agent</shortdesc>
d5211c
+
d5211c
+<parameters>
d5211c
+
d5211c
+<parameter name="binary">
d5211c
+    <longdesc lang="en">Location of the corosync-qnetd binary</longdesc>
d5211c
+    <shortdesc lang="en">corosync-qnetd binary</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_binary_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="qnetd_opts">
d5211c
+    <longdesc lang="en">
d5211c
+        Additional options for corosync-qnetd binary. "-4" for example.
d5211c
+    </longdesc>
d5211c
+    <shortdesc lang="en">corosync-qnetd extra options</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_qnetd_opts_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="qnetd_tool_binary">
d5211c
+    <longdesc lang="en">
d5211c
+        The absolute path to the corosync-qnetd-tool for monitoring with OCF_CHECK_LEVEL greater zero.
d5211c
+    </longdesc>
d5211c
+    <shortdesc lang="en">The absolute path to the corosync-qnetd-tool binary</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_qnetd_tool_binary_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="ip">
d5211c
+    <longdesc lang="en">
d5211c
+        IP address to listen on. By default the daemon listens on all addresses (wildcard).
d5211c
+    </longdesc>
d5211c
+    <shortdesc lang="en">IP address to listen on</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_ip_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="port">
d5211c
+    <longdesc lang="en">
d5211c
+        TCP port to listen on. Default port is 5403.
d5211c
+    </longdesc>
d5211c
+    <shortdesc lang="en">TCP port to listen on</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_port_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="nss_db_dir">
d5211c
+    <longdesc lang="en">
d5211c
+        Location of the corosync-qnetd nss db directory (empty for default - usually /etc/corosync/qnetd/nssdb)
d5211c
+    </longdesc>
d5211c
+    <shortdesc lang="en">corosync-qnetd nss db directory</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_nss_db_dir_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="pid">
d5211c
+    <longdesc lang="en">
d5211c
+        Location of the corosync-qnetd pid/lock
d5211c
+    </longdesc>
d5211c
+    <shortdesc lang="en">corosync-qnetd pid file</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_pid_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="ipc_sock">
d5211c
+    <longdesc lang="en">
d5211c
+        Location of the corosync-qnetd ipc socket
d5211c
+    </longdesc>
d5211c
+    <shortdesc lang="en">corosync-qnetd ipc socket file</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_ipc_sock_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="user">
d5211c
+    <longdesc lang="en">User running corosync-qnetd</longdesc>
d5211c
+    <shortdesc lang="en">corosync-qnetd user</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_user_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+<parameter name="group">
d5211c
+    <longdesc lang="en">Group running corosync-qnetd</longdesc>
d5211c
+    <shortdesc lang="en">corosync-qnetd group</shortdesc>
d5211c
+    <content type="string" default="${OCF_RESKEY_group_default}" />
d5211c
+</parameter>
d5211c
+
d5211c
+</parameters>
d5211c
+
d5211c
+<actions>
d5211c
+<action name="start" timeout="20s" />
d5211c
+<action name="stop" timeout="20s" />
d5211c
+<action name="status" timeout="20s" />
d5211c
+<action name="monitor" depth="0" timeout="20s" interval="10s" start-delay="10s" />
d5211c
+<action name="validate-all" timeout="20s" />
d5211c
+<action name="meta-data" timeout="20s" />
d5211c
+</actions>
d5211c
+</resource-agent>
d5211c
+END
d5211c
+}
d5211c
+
d5211c
+corosync_qnetd_status() {
d5211c
+    ocf_pidfile_status "${OCF_RESKEY_pid}" > /dev/null 2>&1
d5211c
+    case "$?" in
d5211c
+        0)
d5211c
+            rc="$OCF_SUCCESS"
d5211c
+            ;;
d5211c
+        1|2)
d5211c
+            rc="$OCF_NOT_RUNNING"
d5211c
+            ;;
d5211c
+        *)
d5211c
+            rc="$OCF_ERR_GENERIC"
d5211c
+            ;;
d5211c
+    esac
d5211c
+
d5211c
+    return "$rc"
d5211c
+}
d5211c
+
d5211c
+corosync_qnetd_start() {
d5211c
+    corosync_qnetd_validate_all
d5211c
+    rc="$?"
d5211c
+
d5211c
+    if [ "$rc" -ne 0 ]; then
d5211c
+        return "$rc"
d5211c
+    fi
d5211c
+
d5211c
+    # if resource is already running,no need to continue code after this.
d5211c
+    if corosync_qnetd_status; then
d5211c
+        ocf_log info "corosync-qnetd is already running"
d5211c
+        return "${OCF_SUCCESS}"
d5211c
+    fi
d5211c
+
d5211c
+    pid_dir=$(dirname "${OCF_RESKEY_pid}")
d5211c
+    sock_dir=$(dirname "${OCF_RESKEY_ipc_sock}")
d5211c
+
d5211c
+    for d in "$pid_dir" "$sock_dir";do
d5211c
+        if [ ! -d "$d" ];then
d5211c
+            mkdir -p "$d"
d5211c
+            chmod 0770 "$d"
d5211c
+            chown "${OCF_RESKEY_user}:${OCF_RESKEY_group}" "$d"
d5211c
+        fi
d5211c
+    done
d5211c
+
d5211c
+    params="-S \"local_socket_file=${OCF_RESKEY_ipc_sock}\" -S \"lock_file=${OCF_RESKEY_pid}\""
d5211c
+
d5211c
+    if [ -n "${OCF_RESKEY_nss_db_dir}" ];then
d5211c
+        params="$params -S \"nss_db_dir=${OCF_RESKEY_nss_db_dir}\""
d5211c
+    fi
d5211c
+
d5211c
+    if [ -n "${OCF_RESKEY_ip}" ];then
d5211c
+        params="$params -l \"${OCF_RESKEY_ip}\""
d5211c
+    fi
d5211c
+
d5211c
+    if [ -n "${OCF_RESKEY_port}" ];then
d5211c
+        params="$params -p \"${OCF_RESKEY_port}\""
d5211c
+    fi
d5211c
+
d5211c
+    params="$params ${OCF_RESKEY_qnetd_opts}"
d5211c
+
d5211c
+    ocf_run "$SU" -s "/bin/sh" "${OCF_RESKEY_user}" -c "${OCF_RESKEY_binary} $params"
d5211c
+
d5211c
+    while :; do
d5211c
+        corosync_qnetd_monitor "debug"
d5211c
+        rc="$?"
d5211c
+
d5211c
+        if [ "$rc" -eq "${OCF_SUCCESS}" ]; then
d5211c
+            break
d5211c
+        fi
d5211c
+        sleep 1
d5211c
+
d5211c
+        ocf_log debug "corosync-qnetd still hasn't started yet. Waiting..."
d5211c
+    done
d5211c
+
d5211c
+    ocf_log info "corosync-qnetd started"
d5211c
+    return "${OCF_SUCCESS}"
d5211c
+}
d5211c
+
d5211c
+corosync_qnetd_stop() {
d5211c
+    corosync_qnetd_status
d5211c
+
d5211c
+    if [ "$?" -ne "$OCF_SUCCESS" ]; then
d5211c
+        # Currently not running. Nothing to do.
d5211c
+        ocf_log info "corosync-qnetd is already stopped"
d5211c
+
d5211c
+        return "$OCF_SUCCESS"
d5211c
+    fi
d5211c
+
d5211c
+    pid=$(cat "${OCF_RESKEY_pid}")
d5211c
+    kill "$pid"
d5211c
+
d5211c
+    # Wait for process to stop
d5211c
+    while corosync_qnetd_monitor "debug"; do
d5211c
+        sleep 1
d5211c
+    done
d5211c
+
d5211c
+    ocf_log info "corosync-qnetd stopped"
d5211c
+    return "$OCF_SUCCESS"
d5211c
+}
d5211c
+
d5211c
+corosync_qnetd_monitor() {
d5211c
+    loglevel=${1:-err}
d5211c
+
d5211c
+    corosync_qnetd_status
d5211c
+    rc="$?"
d5211c
+
d5211c
+    if [ "$rc" -ne "$OCF_SUCCESS" ];then
d5211c
+        return "$rc"
d5211c
+    fi
d5211c
+
d5211c
+    out=$("${OCF_RESKEY_qnetd_tool_binary}" -s -p "${OCF_RESKEY_ipc_sock}" 2>&1 >/dev/null)
d5211c
+    rc="$?"
d5211c
+
d5211c
+    if [ "$rc" != 0 ];then
d5211c
+        ocf_log "$loglevel" "$out"
d5211c
+    fi
d5211c
+
d5211c
+    case "$rc" in
d5211c
+        "0") rc="$OCF_SUCCESS" ;;
d5211c
+        "3") rc="$OCF_NOT_RUNNING" ;;
d5211c
+        *) rc="$OCF_ERR_GENERIC" ;;
d5211c
+    esac
d5211c
+
d5211c
+    return "$rc"
d5211c
+}
d5211c
+
d5211c
+corosync_qnetd_validate_all() {
d5211c
+    check_binary "${OCF_RESKEY_binary}"
d5211c
+
d5211c
+    check_binary "${OCF_RESKEY_qnetd_tool_binary}"
d5211c
+}
d5211c
+
d5211c
+
d5211c
+# **************************** MAIN SCRIPT ************************************
d5211c
+
d5211c
+# Make sure meta-data and usage always succeed
d5211c
+case "$__OCF_ACTION" in
d5211c
+    meta-data)
d5211c
+        corosync_qnetd_meta_data
d5211c
+        exit "$OCF_SUCCESS"
d5211c
+        ;;
d5211c
+    usage|help)
d5211c
+        corosync_qnetd_usage
d5211c
+        exit "$OCF_SUCCESS"
d5211c
+        ;;
d5211c
+esac
d5211c
+
d5211c
+# This OCF agent script need to be run as root user.
d5211c
+if ! ocf_is_root; then
d5211c
+        echo "$0 agent script need to be run as root user."
d5211c
+        ocf_log debug "$0 agent script need to be run as root user."
d5211c
+        exit "$OCF_ERR_GENERIC"
d5211c
+fi
d5211c
+
d5211c
+# Translate each action into the appropriate function call
d5211c
+case "$__OCF_ACTION" in
d5211c
+    start)
d5211c
+        corosync_qnetd_start
d5211c
+        ;;
d5211c
+    stop)
d5211c
+        corosync_qnetd_stop
d5211c
+        ;;
d5211c
+    status)
d5211c
+        corosync_qnetd_status
d5211c
+        ;;
d5211c
+    monitor)
d5211c
+        corosync_qnetd_monitor
d5211c
+        ;;
d5211c
+    validate-all)
d5211c
+        corosync_qnetd_validate_all
d5211c
+        ;;
d5211c
+    *)
d5211c
+        corosync_qnetd_usage
d5211c
+        exit "$OCF_ERR_UNIMPLEMENTED"
d5211c
+        ;;
d5211c
+esac
d5211c
+
d5211c
+rc="$?"
d5211c
+exit "$rc"
d5211c
+# End of this script