does not send mail despite Unattended-Upgrade::Mail set

Bug #136720 reported by Ernst Kloppenburg
10
Affects Status Importance Assigned to Milestone
unattended-upgrades (Ubuntu)
Fix Released
Undecided
Michael Vogt

Bug Description

Binary package hint: unattended-upgrades

(feisty)

I have configured Unattended-Upgrade::Mail and can verify this with:
$ apt-config dump| grep Mail
Unattended-Upgrade::Mail "";
Unattended-Upgrade::Mail:: "root@localhost";

But after a run of /etc/cron.daily/apt, the last line of /var/log/unattended-upgrades/unattended-upgrades.log still is:
2007-09-02 10:08:30,532 INFO All upgrades installed

Then I looked at usr/bin/unattended-upgrade and pasted some of the python
code into a python shell:

# python
Python 2.5.1 (r251:54863, May 2 2007, 16:56:35)
[GCC 4.1.2 (Ubuntu 4.1.2-0ubuntu4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import apt_pkg
>>> email = apt_pkg.Config.Find("Unattended-Upgrade::Mail", "")
>>> print email

The output is empty! For other configuration items the command works, like apt_pkg.Config.Find("Acquire::http::Proxy")

There seems to be something wrong with the access to the configuration variables.

Revision history for this message
John Edwards (john-cornerstonelinux) wrote :

I'm not an expert on the unattended-upgrades package or the Python apt module, so some of this could be wrong.

How have you defined the mail variable in the /etc/apt/apt.conf.d/ files?

It is like this?
Unattended-Upgrade::Mail {
        "<email address hidden>";
};

If so then I think this problem is that syntax defines a list, which is supposed to be read by the apt_pkg.Config.FindValueList function, eg:
apt_pkg.Config.FindValueList("Unattended-Upgrade::Allowed-Origins")

The unattended-upgrades python code expects the Unattended-Upgrade::Mail variable to be a single value and not a list, so I think it should look like this:
Unattended-Upgrade::Mail "<email address hidden>";

Using the second form produces the correct values, but I've not yet tested that it will send any email.

Would you be able to try again using that style and let me know if it works or not?

Revision history for this message
John Edwards (john-cornerstonelinux) wrote :

Also the script uses the "mail" binary from the "mailx" package to send the email, but there is no dependency listed so it is not installed automatically.

So could you please check that you have the "mailx" package installed?

Revision history for this message
Ernst Kloppenburg (ernst-kloppenburg) wrote :

Answer to the first comment (https://bugs.launchpad.net/ubuntu/+source/unattended-upgrades/+bug/136720/comments/1)

I had defined the mail variable in apt.conf.d/50unattended-upgrades as
 Unattended-Upgrade::Mail {
         "root@localhost";
 };

Now I tried the change you suggested:
Unattended-Upgrade::Mail "root@localhost";

Still, the python code
>>> import apt_pkg
>>> email = apt_pkg.Config.Find("Unattended-Upgrade::Mail", "")
>>> print email
produces an empty result for me.

Revision history for this message
Ernst Kloppenburg (ernst-kloppenburg) wrote :

to the second comment: mailx _is_ installed and works

Revision history for this message
John Edwards (john-cornerstonelinux) wrote :

Have you also imported the python apt module with "import apt"? Eg:

>>> import apt, apt_pkg
>>> email = apt_pkg.Config.Find("Unattended-Upgrade::Mail", "")
>>> print email

You should notice the loading of the apt module as it prints a warning message about the API not being stable yet.

If that doesn't work then you could try a full dump of the config:
    apt-config dump | grep -i mail

Revision history for this message
Ernst Kloppenburg (ernst-kloppenburg) wrote :

no, I had not imported the python apt module (I wonder why apt_pkg did not complain?).

Now I have, and now
email = apt_pkg.Config.Find("Unattended-Upgrade::Mail", "")
indeed yields the configured mail address. Very good!

So my configuration really was wrong (with Unattended-Upgrade::Mail configured as a list). Some complaint of unattended-upgrades in the log file would have been in order...

Thanks.

Revision history for this message
John Edwards (john-cornerstonelinux) wrote :

Looking at the python code in unattended-upgrade it could be a little difficult to include an info line in the log file because apt_pkg.Config.Find returns the same for an incorrect config as for no config at all. It would have to do an incorrect

Perhaps a better method is to add a clear example of the syntax in the comments of the example config file. See bug #136452:
    https://bugs.launchpad.net/ubuntu/+source/unattended-upgrades/+bug/136452

Revision history for this message
Nathan de Vries (atnan) wrote :

Was there a conclusion to this issue? The script ("/usr/bin/unattended-upgrade") currently only imports apt_pkg & apt_inst, so apt_pkg.Config.Find() still yields no result despite the Unattended-Upgrade::Mail option being configured correctly.

Revision history for this message
Ernst Kloppenburg (ernst-kloppenburg) wrote :

when the configuration is done correctly as explained in the first comment (https://bugs.launchpad.net/ubuntu/+source/unattended-upgrades/+bug/136720/comments/1), everything works fine, mails are sent.

Revision history for this message
John Edwards (john-cornerstonelinux) wrote :

Hi Nathan

1)
Which version of Ubuntu and the unattended-upgrades package are you using?
I believe the mail option was added in Feisty (Ubuntu 7.04) and is not available in early versions.

2)
You say that the version of the /usr/bin/unattended-upgrade script you are using does only import apt_pkg and apt_inst, but all of the versions I've seen from 0.2 to 0.25 include a seperate import apt line a few lines later, usually in the following section:

----------------------------------------
import warnings
warnings.filterwarnings("ignore", "apt API not stable yet", FutureWarning)
import apt
import logging
----------------------------------------

Could you also check this by running:
    grep 'import.*apt' /usr/bin/unattended-upgrade

3)
There is also an undeclared dependency on the mailx package - see bug #137994: https://bugs.launchpad.net/ubuntu/+source/unattended-upgrades/+bug/137994

So make sure that the mail binary from the mailx program is installed by running:
    ls -la /usr/bin/mail

Or you can try my patch to use Python's own smtplib to send the emails.

Revision history for this message
Nathan de Vries (atnan) wrote :

Ah. Installing mailx did it, thanks guys.

Revision history for this message
Michael Vogt (mvo) wrote :

Thanks for your bugreport.

This should be fixed with a better example in the configuration file and in the README file in hardy now.

Changed in unattended-upgrades:
assignee: nobody → mvo
status: New → Fix Committed
Michael Vogt (mvo)
Changed in unattended-upgrades:
status: Fix Committed → Fix Released
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.