fsfreeze-hook 1.1 KB

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