Created
January 9, 2026 20:39
-
-
Save vebutton/08bb61991d2c31daa10e28a9fd390be5 to your computer and use it in GitHub Desktop.
Simple QGA log script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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