From: Darrick J. Wong <darrick.wong@xxxxxxxxxx> Create a failure reporting service for when xfs_scrub_all fails. This is probably a debug-only patch. Signed-off-by: Darrick J. Wong <darrick.wong@xxxxxxxxxx> --- scrub/Makefile | 3 ++- scrub/xfs_scrub_all_fail | 24 ++++++++++++++++++++++++ scrub/xfs_scrub_all_fail.service.in | 11 +++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 scrub/xfs_scrub_all_fail create mode 100644 scrub/xfs_scrub_all_fail.service.in diff --git a/scrub/Makefile b/scrub/Makefile index 47c887eb..50d16121 100644 --- a/scrub/Makefile +++ b/scrub/Makefile @@ -18,7 +18,7 @@ XFS_SCRUB_ALL_PROG = xfs_scrub_all XFS_SCRUB_ARGS = -b -n ifeq ($(HAVE_SYSTEMD),yes) INSTALL_SCRUB += install-systemd -SYSTEMD_SERVICES = xfs_scrub@.service xfs_scrub_all.service xfs_scrub_all.timer xfs_scrub_fail@.service +SYSTEMD_SERVICES = xfs_scrub@.service xfs_scrub_all.service xfs_scrub_all.timer xfs_scrub_fail@.service xfs_scrub_all_fail.service OPTIONAL_TARGETS += $(SYSTEMD_SERVICES) endif ifeq ($(HAVE_CROND),yes) @@ -133,6 +133,7 @@ install-systemd: default $(SYSTEMD_SERVICES) $(INSTALL) -m 644 $(SYSTEMD_SERVICES) $(SYSTEMD_SYSTEM_UNIT_DIR) $(INSTALL) -m 755 -d $(PKG_LIB_DIR)/$(PKG_NAME) $(INSTALL) -m 755 xfs_scrub_fail $(PKG_LIB_DIR)/$(PKG_NAME) + $(INSTALL) -m 755 xfs_scrub_all_fail $(PKG_LIB_DIR)/$(PKG_NAME) install-crond: default $(CRONTABS) $(INSTALL) -m 755 -d $(CROND_DIR) diff --git a/scrub/xfs_scrub_all_fail b/scrub/xfs_scrub_all_fail new file mode 100755 index 00000000..8391abc8 --- /dev/null +++ b/scrub/xfs_scrub_all_fail @@ -0,0 +1,24 @@ +#!/bin/bash + +# Email logs of failed xfs_scrub_all unit runs + +mailer=/usr/sbin/sendmail +recipient="$1" +test -z "${recipient}" && exit 0 +hostname="$(hostname -f 2>/dev/null)" +test -z "${hostname}" && hostname="${HOSTNAME}" +if [ ! -x "${mailer}" ]; then + echo "${mailer}: Mailer program not found." + exit 1 +fi + +(cat << ENDL +To: $1 +From: <xfs_scrub_all@${hostname}> +Subject: xfs_scrub_all failure on ${mntpoint} + +So sorry, the automatic xfs_scrub_all on ${hostname} failed. + +A log of what happened follows: +ENDL +systemctl status --full --lines 4294967295 "xfs_scrub_all") | "${mailer}" -t -i diff --git a/scrub/xfs_scrub_all_fail.service.in b/scrub/xfs_scrub_all_fail.service.in new file mode 100644 index 00000000..2d85db28 --- /dev/null +++ b/scrub/xfs_scrub_all_fail.service.in @@ -0,0 +1,11 @@ +[Unit] +Description=Online XFS Metadata Check for All Filesystems Failure Reporting for %I +Documentation=man:xfs_scrub_all(8) + +[Service] +Type=oneshot +Environment=EMAIL_ADDR=root +ExecStart=@pkg_lib_dir@/@pkg_name@/xfs_scrub_all_fail "${EMAIL_ADDR}" +User=mail +Group=mail +SupplementaryGroups=systemd-journal