sudo87 commented on code in PR #13090:
URL: https://github.com/apache/cloudstack/pull/13090#discussion_r4358353447


##########
scripts/vm/hypervisor/kvm/kvmha-fence.sh:
##########
@@ -0,0 +1,263 @@
+#!/bin/bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# Shared fence-action helper for kvmheartbeat.sh, kvmspheartbeat.sh and 
kvmsmpheartbeat.sh.
+# Sourced by those scripts; do not invoke directly.
+#
+# kvm.heartbeat.fence.action in agent.properties selects the action:
+#   hard-reboot (default), graceful-reboot, restart-agent, or log-only (only 
writes to
+#   syslog). Any other value falls back to hard-reboot.
+#
+# restart-agent and log-only leave the host up. Once the heartbeat is stale 
the management
+# server may declare this host Down and HA may start its VMs on another host, 
so both
+# actions first stop every VM still running here; if any VM cannot be stopped 
the fence
+# falls back to hard-reboot. kvm.heartbeat.fence.include.system.vms=false 
limits that step
+# to user VMs: system VMs (virtual routers, console proxy, secondary storage 
and internal
+# LB VMs) are left running and do not count towards the fallback.
+# kvm.heartbeat.fence.keep.vms.running=true skips the step entirely and wins 
over
+# include.system.vms; it is only safe when no VM on this host can be restarted 
elsewhere.
+#
+# The agent kills this script once heartbeat.update.timeout (60 s by default) 
runs out, and
+# on hung storage stopping a VM can block for much longer than that. So before 
stopping any
+# VM the fence arms a detached deadman that survives the agent killing this 
script: unless
+# every VM the fence must stop is confirmed gone within 
kvm.heartbeat.fence.stop.vms.timeout
+# seconds (default 30, keep it below heartbeat.update.timeout), the deadman 
hard-reboots the
+# host. Each virsh call is also bounded by coreutils timeout, when present, to 
at most 10 s
+# (or the budget if lower) so one stuck domain cannot use up the whole budget.
+#
+# Properties read from agent.properties:
+#   kvm.heartbeat.fence.action              hard-reboot (default), 
graceful-reboot,
+#                                           restart-agent or log-only
+#   kvm.heartbeat.fence.keep.vms.running    false (default); true stops nothing
+#   kvm.heartbeat.fence.include.system.vms  true (default); false stops only 
user VMs
+#   kvm.heartbeat.fence.stop.vms.timeout    30 (default); seconds the VM stop 
phase may take
+#                                           before the deadman hard-reboots 
the host. A value
+#                                           that is not a positive integer 
means 30.
+#
+# Usage from caller:
+#   source "$(dirname "$0")/kvmha-fence.sh"
+#   fence_action "kvmheartbeat.sh"   # script name passed for log tagging
+
+AGENT_PROPS="${AGENT_PROPS:-/etc/cloudstack/agent/agent.properties}"
+FENCE_LOGGER="${FENCE_LOGGER:-/usr/bin/logger}"
+FENCE_SYSRQ_TRIGGER="${FENCE_SYSRQ_TRIGGER:-/proc/sysrq-trigger}"
+# Where the deadman keeps its arm file; /run is a local tmpfs, so hung storage 
cannot block it.
+FENCE_DEADMAN_DIR="${FENCE_DEADMAN_DIR:-/run/cloudstack-agent/kvmha-fence}"
+FENCE_STOP_VMS_TIMEOUT_DEFAULT=30
+FENCE_VIRSH_TIMEOUT_MAX=10
+# Per-call virsh timeout in seconds; empty means unbounded. Set by 
fence_action.
+FENCE_VIRSH_TIMEOUT=""
+FENCE_DEADMAN_ARM=""
+
+read_agent_property() {
+  [ -r "$AGENT_PROPS" ] || return 0
+  grep "^$1=" "$AGENT_PROPS" | tail -n 1 | cut -d= -f2- | tr -d '[:space:]'

Review Comment:
   grep "^$1=" only matches key=value
   `kvm.heartbeat.fence.keep.vms.running = true` is valid in agent.properties 
but ignored here, so the VMs get stopped despite the opt-out. Please make it 
whitespace-tolerant



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to