smartd sends mail before network is up on boot

Bug #1784191 reported by Barry Kolts
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
smartmontools (Ubuntu)
Triaged
Wishlist
Unassigned

Bug Description

 lsb_release -rd
Description: Ubuntu 18.04.1 LTS
Release: 18.04

apt-cache policy smartmontools
smartmontools:
  Installed: 6.5+svn4324-1
  Candidate: 6.5+svn4324-1
  Version table:
 *** 6.5+svn4324-1 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status

Expected behavior:
smartd sends a test email on boot.

What happens:
No mail is recieved. sSMTP logs "Unable to locate Mail server" and "cannot open mailserver:25". I'm using the same smartd.conf and my script smartd calls that I used on 14.04, which worked flawlessly.

Work around:
I had my script sleep 5 seconds before sending the mail. This worked fine leading me to believe smartd is calling my script before networking is up. But this is not an elegant solution. So I copied /lib/systemd/system/smartd.service to /etc/systemd/system/smartd.service and add the line "After=network-online.target"This worked fine. So the full smartd.sevice unit is:
[Unit]
Description=Self Monitoring and Reporting Technology (SMART) Daemon
Documentation=man:smartd(8) man:smartd.conf(5)
After=network-online.target

[Service]
EnvironmentFile=-/etc/default/smartmontools
ExecStart=/usr/sbin/smartd -n $smartd_opts
ExecReload=/bin/kill -HUP $MAINPID
StandardOutput=syslog

[Install]
WantedBy=multi-user.target

I haven't got any other machines to test this on. So I hope the report will help some one else

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Thanks for filing this bug in Ubuntu.

smartd won't always require networking, so making such a change distribution-wide is probably not the best solution. You adapted well to your local configuration settings, and I'm glad it worked.

Other MTAs probably would have handled this better I suspect, as ssmtp doesn't handle queueing.

Also note that -M test in smartd.conf is not about sending a test email on boot, but on restart of the smartd daemon. It can happen anytime, not just during boot. An upgrade of the package could trigger that, for example. In which case it would work, as network is already up.

It feels like a corner case, and I'm not sure there is an elegant solution that applies to all cases. Always depending on the network online target would increase boot times unnecessarily.

Changed in smartmontools (Ubuntu):
importance: Undecided → Wishlist
status: New → Triaged
Revision history for this message
Barry Kolts (bhkolts) wrote :

Andreas,
Thanks for your response. I agree with your assessment, this is a corner case. I use ssmtp instead of a MTA because I just want to send an email from a script. As in the case of smartd,I have smartd call my script which sends the test message and also the output of smartctl -H which reports the health of the hard drive. So upon start up I get an email reporting the health of my drives. So this is defiantly a local preference.

For completeness I have modified my work around to be more inline with systemd's philosophy. Instead of coping /lib/systemd/system/smartd.service to /etc/systemd/system, I created the directory /etc/systemd/system/smartd.service.d. In that directory I created the file extend.conf with the folowing contents:

[Unit]
# Added to make sure networking is up before sending mail.
# This covers a local corner case during boot.
After=network-online.target

I wanted to add my change in case someone else had this problem.

Thanks again for your help with this.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.