Skip to content

Instantly share code, notes, and snippets.

@vebutton
Created January 7, 2026 18:14
Show Gist options
  • Select an option

  • Save vebutton/2a1652a3f124d48e458317b5b4bcf8fd to your computer and use it in GitHub Desktop.

Select an option

Save vebutton/2a1652a3f124d48e458317b5b4bcf8fd to your computer and use it in GitHub Desktop.
QGA freeze thaw starter
#!/bin/bash
# Define the directory where logs will be stored
LOG_DIR="/var/log/qemu-agent-hooks"
# Get the type of event (freeze or thaw) passed as the first argument
EVENT_TYPE="$1"
# --- Script Logic ---
# 1. Ensure the log directory exists
mkdir -p "$LOG_DIR"
# 2. Log based on the event type
case "$EVENT_TYPE" in
freeze)
echo "$(date '+%Y-%m-%d %H:%M:%S') - QEMU Agent: FREEZE event triggered." | tee -a "$LOG_DIR/pre_freeze_$(date +%Y%m%d_%H%M%S).txt" > /dev/null
echo "This is where you would put commands to quiesce your application (e.g., flush DB buffers)." | tee -a "$LOG_DIR/pre_freeze_$(date +%Y%m%d_%H%M%S).txt" > /dev/null
;;
thaw)
echo "$(date '+%Y-%m-%d %H:%M:%S') - QEMU Agent: THAW event triggered." | tee -a "$LOG_DIR/post_thaw_$(date +%Y%m%d_%H%M%S).txt" > /dev/null
echo "This is where you would put commands to unquiesce your application (e.g., release DB locks)." | tee -a "$LOG_DIR/post_thaw_$(date +%Y%m%d_%H%M%S).txt" > /dev/null
;;
*)
# Handle unexpected arguments (shouldn't happen with normal qemu-agent calls)
echo "$(date '+%Y-%m-%d %H:%M:%S') - QEMU Agent: Unknown event type '$EVENT_TYPE'." | tee -a "$LOG_DIR/error_log.txt" > /dev/null
exit 1 # Indicate an error if an unknown event type is received
;;
esac
# Exit successfully
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment