systemd MAILTO 替换失败

systemd MAILTO 替换失败

我正在尝试设置systemd当某个单元发生故障时通过电子邮件通知我,就像 Cron 可以设置的那样。我遵循Arch Linux wiki 上的指南

所以我在以下位置设置了一个sendmailshell 脚本/usr/local/bin/systemd-email

#!/bin/bash
/usr/bin/sendmail -t <<ERRMAIL
To: $1
From: systemd <root@$HOSTNAME>
Subject: $2
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8

$(systemctl status --full "$2")
ERRMAIL

然后我在以下位置设置了一个 systemd 服务:/etc/systemd/system/[email protected]

[Unit]
Description=status email for %I to user1

[Service]
Type=oneshot
ExecStart=/usr/local/bin/systemd-email [email protected] %i
User=nobody
Group=systemd-journal

但是,当我测试此设置并运行 时,我收到以下失败消息:systemctl start [email protected]

[email protected] - status email for dbus to user1
   Loaded: loaded (/etc/systemd/system/[email protected]; static; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2015-06-14 10:19:36 MDT; 20min ago
  Process: 31229 ExecStart=/usr/local/bin/systemd-email [email protected] %i (code=exited, status=1/FAILURE)
 Main PID: 31229 (code=exited, status=1/FAILURE)

Jun 14 10:19:36 sindhu systemd[1]: Starting status email for dbus to user1...
Jun 14 10:19:36 sindhu sSMTP[31230]: /etc/ssmtp/ssmtp.conf not found
Jun 14 10:19:36 sindhu sSMTP[31230]: Unable to locate mailhub
Jun 14 10:19:36 sindhu systemd-email[31229]: sendmail: Cannot open mailhub:25
Jun 14 10:19:36 sindhu systemd[1]: [email protected]: main pro...RE
Jun 14 10:19:36 sindhu systemd[1]: Failed to start status email for dbus to ...1.
Jun 14 10:19:36 sindhu systemd[1]: Unit [email protected] ente...1.
Jun 14 10:19:36 sindhu systemd[1]: [email protected] failed.
Hint: Some lines were ellipsized, use -l to show in full.

但是,/etc/ssmtp/ssmtp.conf它实际上存在,并且配置正确(我已经设置了 SSMTP),因此如果我运行类似以下内容:

echo -e "To: [email protected]\nFrom: [email protected]\nSubject: Hello Notification\n\n Hello, this is a test"|ssmtp [email protected]

我按预期/期望收到电子邮件。

同样,如果我运行 shell 脚本,我也会收到电子邮件。systemd-email [email protected] dbus

所以,所有的systemd外部部件似乎都在工作;因此systemd,据我所知,它一定是内在的东西。但我不知道是什么,或者如何解决它。

答案1

该线程解决了我的类似问题。基本上,systemd 会在发送邮件之前杀死应该发送邮件的子进程。修复方法是将“set sendwait”添加到/etc/mail.rc,但我的设置与您所描述的略有不同。

ExecStart 中的 /usr/bin/mail 调用不发送任何邮件

相关内容