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


##########
scripts/vm/hypervisor/kvm/kvmspheartbeat.sh:
##########
@@ -58,9 +58,41 @@ deleteVMs() {
 
 if [ "$cflag" == "1" ]
 then
-  /usr/bin/logger -t heartbeat "kvmspheartbeat.sh will reboot system because 
it was unable to write the heartbeat to the storage."
-  sync &
-  sleep 5
-  echo b > /proc/sysrq-trigger
-  exit $?
+  # Read fence action from agent.properties (default: reboot for backward 
compatibility).
+  # Allowed values: reboot | graceful-reboot | restart-agent | log-only
+  AGENT_PROPS="/etc/cloudstack/agent/agent.properties"
+  FENCE_ACTION="reboot"
+  if [ -r "$AGENT_PROPS" ]; then
+    val=$(grep -E '^[[:space:]]*kvm\.heartbeat\.fence\.action[[:space:]]*=' 
"$AGENT_PROPS" | tail -n 1 | cut -d= -f2- | tr -d '[:space:]')
+    [ -n "$val" ] && FENCE_ACTION="$val"
+  fi
+
+  case "$FENCE_ACTION" in
+    log-only)
+      /usr/bin/logger -t heartbeat "kvmspheartbeat.sh: heartbeat write to 
storage failed; fence action 'log-only' selected — taking no automatic action. 
Operator must investigate."
+      exit 0
+      ;;
+    restart-agent)
+      /usr/bin/logger -t heartbeat "kvmspheartbeat.sh: heartbeat write to 
storage failed; fence action 'restart-agent' — restarting cloudstack-agent 
(running VMs preserved)."
+      sync &
+      sleep 2
+      systemctl restart cloudstack-agent
+      exit $?
+      ;;
+    graceful-reboot)
+      /usr/bin/logger -t heartbeat "kvmspheartbeat.sh: heartbeat write to 
storage failed; fence action 'graceful-reboot' — rebooting via systemctl 
(allows running VMs to stop cleanly)."
+      sync &
+      sleep 5
+      systemctl reboot
+      exit $?
+      ;;
+    reboot|*)
+      # Original behavior: immediate kernel-level reboot via sysrq-trigger
+      /usr/bin/logger -t heartbeat "kvmspheartbeat.sh will reboot system 
because it was unable to write the heartbeat to the storage."
+      sync &
+      sleep 5
+      echo b > /proc/sysrq-trigger
+      exit $?
+      ;;

Review Comment:
   if this part is generic for both, can keep it in a common script and call 
that with the fence action?



-- 
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