]> git.sesse.net Git - bcachefs-tools-debian/blob - fsck/bcachefsck_fail
cmd_reset_counters
[bcachefs-tools-debian] / fsck / bcachefsck_fail
1 #!/bin/bash
2
3 # SPDX-License-Identifier: GPL-2.0
4 #
5 # Copyright (C) 2023-2024 Oracle.  All Rights Reserved.
6 # Author: Darrick J. Wong <djwong@kernel.org>
7
8 # Email logs of failed bcachefsck and bcachefsck_all unit runs
9
10 recipient="$1"
11 test -z "${recipient}" && exit 0
12 service="$2"
13 test -z "${service}" && exit 0
14 mntpoint="$3"
15
16 hostname="$(hostname -f 2>/dev/null)"
17 test -z "${hostname}" && hostname="${HOSTNAME}"
18
19 mailer="$(command -v sendmail)"
20 if [ ! -x "${mailer}" ]; then
21         echo "${mailer}: Mailer program not found."
22         exit 1
23 fi
24
25 fail_mail_mntpoint() {
26         local scrub_svc
27
28         # Turn the mountpoint into a properly escaped systemd instance name
29         scrub_svc="$(systemd-escape --template "${service}@.service" --path "${mntpoint}")"
30         cat << ENDL
31 To: ${recipient}
32 From: <${service}@${hostname}>
33 Subject: ${service} failure on ${mntpoint}
34 Content-Transfer-Encoding: 8bit
35 Content-Type: text/plain; charset=UTF-8
36
37 So sorry, the automatic ${service} of ${mntpoint} on ${hostname} failed.
38 Please do not reply to this mesage.
39
40 A log of what happened follows:
41 ENDL
42         systemctl status --full --lines 4294967295 "${scrub_svc}"
43 }
44
45 fail_mail() {
46         cat << ENDL
47 To: ${recipient}
48 From: <${service}@${hostname}>
49 Subject: ${service} failure
50
51 So sorry, the automatic ${service} on ${hostname} failed.
52
53 A log of what happened follows:
54 ENDL
55         systemctl status --full --lines 4294967295 "${service}"
56 }
57
58 if [ -n "${mntpoint}" ]; then
59         fail_mail_mntpoint | "${mailer}" -t -i
60 else
61         fail_mail | "${mailer}" -t -i
62 fi
63 exit "${PIPESTATUS[1]}"