FS#49809 - [smartmontools] needs "User=root" in systemd service unit for email notifications with s-nail
Attached to Project:
Arch Linux
Opened by Christopher Singley (csingley) - Wednesday, 22 June 2016, 17:26 GMT
Last edited by freswa (frederik) - Friday, 21 August 2020, 11:13 GMT
Opened by Christopher Singley (csingley) - Wednesday, 22 June 2016, 17:26 GMT
Last edited by freswa (frederik) - Friday, 21 August 2020, 11:13 GMT
|
Details
Description: Contrary to the documentation in the Arch wiki
for S.M.A.R.T., it is not possible simply to configure
core/s-nail to deliver email warnings generated by smartd.
This is because the [Service] stanza in the smartd.service
unit file neglects to set "User=root". As a result, $HOME
remains unset in smartd's environment. When the daemon
invokes /usr/bin/mail, s-nail cannot find ~/.mailrc, it
remains unconfigured, and mail service fails.
The cleanest fix for this is to add "User=root" to the [Service] stanza in /usr/lib/systemd/system/smartd.service, which should have no undesirable side effects. Other possible solutions are: 1. Patch /usr/share/smartmontools/smartd_warning.sh in order to add "export HOME=~". Maintaining such a patch seems undesirable when upstream's code is correct and the bug is internal to Arch's distribution package. 2. Change the wiki documentation and ask users to set all login information in /etc/mail.rc . This is obviously a terrible idea - poor security, inflexible (especially in a multi-user environment) and destined to be clobbered by package updates. 3. Ask users to configure /etc/smartd.conf to override the default "mail" command with a nonstandard wrapper script that sets $HOME before calling /usr/bin/mail. This seems cumbersome and obscure (at odds with upstream's own excellent documentation). So if we want smartmontools to work with s-nail, I think we need to patch the smartd.service unit file. Additional info: * extra/smartmontools 6.5-1 * core/s-nail 14.8.8-1 Steps to reproduce: 1. Create a config for root user at /root/.mailrc. Verify it's working by using /usr/bin/mail to send a test email as root. 2. Install smartmontools and configure /etc/smartd.conf to include "-m someuser@somedomain.tld -M test". 3. systemctl start smartd. 4. Observe the delivery failure of the test email. Note that `journalctl -xe -u smartd` shows that mail delivery fails with the error message from s-nail "No mail for root". 5. Edit /usr/lib/systemd/system/smartd.service to include [Service]\nUser=root. Repeat steps 1-3 above, and observe the successful mail delivery. Thank you! |
This task depends upon
It should have no effect of any kind. System services already run as the root user.
"$USER, $LOGNAME, $HOME, $SHELL
User name (twice), home directory, and the login shell. The variables are set for the units that have User= set, which includes user systemd instances. See passwd(5)."
http://0pointer.de/public/systemd-man/systemd.exec.html#Environment%20variables%20in%20spawned%20processes
So for operations which rely on $HOME being set (such as s-nail with ~/.mailrc), the User needs to be set in the unit file.
I can verify that setting User=root resolves the bug I am reporting. Try it out and see.
Thanks.
> the bug is internal to Arch's distribution package.
service file is provided by upstream.