#! /bin/bash . /usr/src/k_framework/main.sh # ---- VARS ----- VERSION="1.0.3" SCRIPT_NAME="Corosync/Pacemaker/pcsd check" # All possible resources across mor/m4 in regex OR format FAILOVER_RESOURCES="asterisk|httpd|opensips|kamailio|rtpengine|sems|radiusd" TEST=0 # 1 - do not execute changes # ---- FUNCTIONS ----- # ---- MAIN ----- k_config_details k_detect_os k_start if [[ $PCSD_ACTIVE == 0 ]]; then report "Corosync/Pacemaker/pcsd is not installed" 0 k_exit 0 fi if [[ $PCSD_ACTIVE == 1 ]]; then if [[ $VIRTUAL_IP == "" ]]; then report "Corosync/Pacemaker/pcsd is installed but VIRTUAL_IP is NOT configured in system.conf" 1 EXIT_CODE=1 fi for failover_daemon in corosync pacemaker pcsd; do if ! pgrep "$failover_daemon" &> /dev/null; then report "Corosync/Pacemaker/pcsd is installed but $failover_daemon is not running" 1 report " Maybe cluster is stopped? check output of pcs status" fix EXIT_CODE=1 # Exit here as this will propogate nonsensical errors later" k_exit $EXIT_CODE fi done if pcs status 2> /dev/null | grep -Fq 'Failed Resource Actions'; then report "There are failed resource actions:" 1 pcs status | awk '/Failed Resource Actions/{flag=1; next} /Daemon Status/{flag=0} flag' report " pcs resource cleanup resource_name" fix report " for example pcs resource cleanup kamailio" fix report " you can check resource names with command --> pcs resource show" EXIT_CODE=1 fi for failover_daemon in corosync pacemaker pcsd; do failover_daemon_status=$(pcs status 2>/dev/null | grep -F "$failover_daemon"); if echo "$failover_daemon_status" | grep -Fq 'disabled'; then report "$failover_daemon is not enanbled" 1 report " systemctl enable $failover_daemon" fix EXIT_CODE=1 fi done if [[ $centos_version == 7 ]]; then while read -r failover_resource; do if [[ $failover_resource == "kamailio" ]]; then # kamailio uses init scrips, systemcl does not show enable/disable status correctly if k_service_is_enabled_chkcfg "$failover_resource"; then report "Service $failover_resource is managed by corosync, but is enabled in chkconfig" report " systemctl disable $failover_resource" fix fi else if k_service_is_enabled_systemctl "$failover_resource"; then report "Service $failover_resource is managed by corosync, but is enabled in systemctl" report " systemctl disable $failover_resource" fix fi fi done < <(pcs resource show --full | awk '/Resource/ {print $2}' | grep -Ei "$FAILOVER_RESOURCES") elif [[ $ROCKY9 == 1 ]]; then while read -r failover_resource; do if k_service_is_enabled_systemctl "$failover_resource"; then report "Service $failover_resource is managed by corosync, but is enabled in systemctl" report " systemctl disable $failover_resource" fix fi done < <(pcs resource config | awk '/Resource/ {print $2}' | grep -Ei "$FAILOVER_RESOURCES" ) else report "Unssuported OS detected. Exiting" 6 fi fi k_exit $EXIT_CODE