3 # SPDX-License-Identifier: GPL-2.0
5 # Copyright (C) 2023-2024 Oracle. All Rights Reserved.
6 # Author: Darrick J. Wong <djwong@kernel.org>
8 # Email logs of failed bcachefsck and bcachefsck_all unit runs
11 test -z "${recipient}" && exit 0
13 test -z "${service}" && exit 0
16 hostname="$(hostname -f 2>/dev/null)"
17 test -z "${hostname}" && hostname="${HOSTNAME}"
19 mailer="$(command -v sendmail)"
20 if [ ! -x "${mailer}" ]; then
21 echo "${mailer}: Mailer program not found."
25 fail_mail_mntpoint() {
28 # Turn the mountpoint into a properly escaped systemd instance name
29 scrub_svc="$(systemd-escape --template "${service}@.service" --path "${mntpoint}")"
32 From: <${service}@${hostname}>
33 Subject: ${service} failure on ${mntpoint}
34 Content-Transfer-Encoding: 8bit
35 Content-Type: text/plain; charset=UTF-8
37 So sorry, the automatic ${service} of ${mntpoint} on ${hostname} failed.
38 Please do not reply to this mesage.
40 A log of what happened follows:
42 systemctl status --full --lines 4294967295 "${scrub_svc}"
48 From: <${service}@${hostname}>
49 Subject: ${service} failure
51 So sorry, the automatic ${service} on ${hostname} failed.
53 A log of what happened follows:
55 systemctl status --full --lines 4294967295 "${service}"
58 if [ -n "${mntpoint}" ]; then
59 fail_mail_mntpoint | "${mailer}" -t -i
61 fail_mail | "${mailer}" -t -i
63 exit "${PIPESTATUS[1]}"