1*96610da2STomoki Sekiyama#!/bin/sh
2*96610da2STomoki Sekiyama
3*96610da2STomoki Sekiyama# This script is executed when a guest agent receives fsfreeze-freeze and
4*96610da2STomoki Sekiyama# fsfreeze-thaw command, if it is specified in --fsfreeze-hook (-F)
5*96610da2STomoki Sekiyama# option of qemu-ga or placed in default path (/etc/qemu/fsfreeze-hook).
6*96610da2STomoki Sekiyama# When the agent receives fsfreeze-freeze request, this script is issued with
7*96610da2STomoki Sekiyama# "freeze" argument before the filesystem is frozen. And for fsfreeze-thaw
8*96610da2STomoki Sekiyama# request, it is issued with "thaw" argument after filesystem is thawed.
9*96610da2STomoki Sekiyama
10*96610da2STomoki SekiyamaLOGFILE=/var/log/qga-fsfreeze-hook.log
11*96610da2STomoki SekiyamaFSFREEZE_D=$(dirname -- "$0")/fsfreeze-hook.d
12*96610da2STomoki Sekiyama
13*96610da2STomoki Sekiyama# Check whether file $1 is a backup or rpm-generated file and should be ignored
14*96610da2STomoki Sekiyamais_ignored_file() {
15*96610da2STomoki Sekiyama    case "$1" in
16*96610da2STomoki Sekiyama        *~ | *.bak | *.orig | *.rpmnew | *.rpmorig | *.rpmsave | *.sample)
17*96610da2STomoki Sekiyama            return 0 ;;
18*96610da2STomoki Sekiyama    esac
19*96610da2STomoki Sekiyama    return 1
20*96610da2STomoki Sekiyama}
21*96610da2STomoki Sekiyama
22*96610da2STomoki Sekiyama# Iterate executables in directory "fsfreeze-hook.d" with the specified args
23*96610da2STomoki Sekiyama[ ! -d "$FSFREEZE_D" ] && exit 0
24*96610da2STomoki Sekiyamafor file in "$FSFREEZE_D"/* ; do
25*96610da2STomoki Sekiyama    is_ignored_file "$file" && continue
26*96610da2STomoki Sekiyama    [ -x "$file" ] || continue
27*96610da2STomoki Sekiyama    printf "$(date): execute $file $@\n" >>$LOGFILE
28*96610da2STomoki Sekiyama    "$file" "$@" >>$LOGFILE 2>&1
29*96610da2STomoki Sekiyama    STATUS=$?
30*96610da2STomoki Sekiyama    printf "$(date): $file finished with status=$STATUS\n" >>$LOGFILE
31*96610da2STomoki Sekiyamadone
32*96610da2STomoki Sekiyama
33*96610da2STomoki Sekiyamaexit 0
34