Skip to content

Commit 3528688

Browse files
committed
Fix v-restart-mail to report the correct service that failed and attach relevant debug logs to the email
1 parent 5152860 commit 3528688

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

bin/v-restart-mail

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ source $HESTIA/conf/hestia.conf
1515
PATH="$PATH:/usr/local/sbin:/sbin:/usr/sbin:/root/bin"
1616

1717
send_email_report() {
18+
local mail_service="$1"
19+
journalctl --no-pager --reverse --since=-1m --unit "$mail_service" >> "$tmpfile" 2>&1
1820
email=$(grep CONTACT $HESTIA/data/users/admin/user.conf)
1921
email=$(echo "$email" | cut -f 2 -d "'")
20-
tmpfile=$(mktemp)
21-
subj="$(hostname): $MAIL_SYSTEM restart failed"
22-
service $MAIL_SYSTEM configtest >> $tmpfile 2>&1
23-
service $MAIL_SYSTEM restart >> $tmpfile 2>&1
24-
cat $tmpfile |$SENDMAIL -s "$subj" $email
25-
rm -f $tmpfile
22+
subj="$(hostname): $mail_service restart failed"
23+
cat "$tmpfile" |$SENDMAIL -s "$subj" $email
24+
[[ -f "$tmpfile" ]] && rm -f $tmpfile
2625
}
2726

2827

@@ -46,19 +45,20 @@ if [ -z "$MAIL_SYSTEM" ] || [ "$MAIL_SYSTEM" = 'remote' ]; then
4645
exit
4746
fi
4847

48+
tmpfile=$(mktemp)
4949
# Restart IMAP system if present
5050
if [ ! -z "$IMAP_SYSTEM" ]; then
51-
$BIN/v-restart-service $IMAP_SYSTEM > /dev/null 2>&1
51+
$BIN/v-restart-service $IMAP_SYSTEM >> $tmpfile 2>&1
5252
if [ $? -ne 0 ]; then
53-
send_email_report
53+
send_email_report "$IMAP_SYSTEM"
5454
check_result $E_RESTART "$IMAP_SYSTEM restart failed"
5555
fi
5656
fi
5757

5858
# Restart mail system
59-
$BIN/v-restart-service $MAIL_SYSTEM > /dev/null 2>&1
59+
$BIN/v-restart-service $MAIL_SYSTEM >> $tmpfile 2>&1
6060
if [ $? -ne 0 ]; then
61-
send_email_report
61+
send_email_report "$MAIL_SYSTEM"
6262
check_result $E_RESTART "$MAIL_SYSTEM restart failed"
6363
fi
6464

@@ -72,4 +72,5 @@ fi
7272
# Hestia #
7373
#----------------------------------------------------------#
7474

75+
[[ -f "$tmpfile" ]] && rm -f $tmpfile
7576
exit

0 commit comments

Comments
 (0)