anacron upstart job does not inherit pam_env config from cron, causes, update-notifier to not use configured system proxy

Bug #1317920 reported by Peter Parzer on 2014-05-09
20
This bug affects 4 people
Affects Status Importance Assigned to Milestone
anacron (Ubuntu)
High
Unassigned
update-notifier (Ubuntu)
Undecided
Unassigned

Bug Description

The script /etc/cron.daily/update-notifier-common fails trying to download extra files with package-data-downloader when called by cron.

/etc/cron.daily/update-notifier-common:
Traceback (most recent call last):
  File "/usr/lib/update-notifier/package-data-downloader", line 239, in process_download_requests
    dest_file = urllib.urlretrieve(files[i])[0]
  File "/usr/lib/python2.7/urllib.py", line 94, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
  File "/usr/lib/python2.7/urllib.py", line 240, in retrieve
    fp = self.open(url, data)
  File "/usr/lib/python2.7/urllib.py", line 208, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/urllib.py", line 345, in open_http
    h.endheaders(data)
  File "/usr/lib/python2.7/httplib.py", line 969, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 829, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 791, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 772, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
IOError: [Errno socket error] [Errno 101] Network is unreachable
flashplugin-installer: downloading http://archive.canonical.com/pool/partner/a/adobe-flashplugin/adobe-flashplugin_11.2.202.356.orig.tar.gz

Update-notifier-common works wenn called from the terminal. The system proxy is correctly set in /etc/environment and /etc/apt/apt.conf. The problem is fixed by adding the following 2 lines at the start of /etc/cron.daily/update-notifier-common:

. /etc/environment
export http_proxy

Peter

ProblemType: Bug
DistroRelease: Ubuntu 14.04
Package: update-notifier 0.154.1
ProcVersionSignature: Ubuntu 3.13.0-24.47-generic 3.13.9
Uname: Linux 3.13.0-24-generic x86_64
ApportVersion: 2.14.1-0ubuntu3
Architecture: amd64
CurrentDesktop: Unity
Date: Fri May 9 15:37:41 2014
InstallationDate: Installed on 2014-04-29 (9 days ago)
InstallationMedia: Ubuntu 14.04 LTS "Trusty Tahr" - Release amd64 (20140417)
ProcEnviron:
 TERM=xterm
 PATH=(custom, no user)
 XDG_RUNTIME_DIR=<set>
 LANG=de_DE.UTF-8
 SHELL=/bin/bash
SourcePackage: update-notifier
UpgradeStatus: No upgrade log present (probably fresh install)

Peter Parzer (peter-parzer) wrote :
Steve Langasek (vorlon) wrote :

The cronjob is run from cron; cron is configured via /etc/pam.d/cron to use pam_env.so by default, which reads /etc/environment. Why is this not working on your system?

Individual cron jobs should definitely not be expected to source /etc/environment directly.

Changed in update-notifier (Ubuntu):
status: New → Incomplete
Peter Parzer (peter-parzer) wrote :

I created two simple cron scripts on a new installation of Ubuntu 14.04 amd64 with all updates installed (the only additional package I installed was cifs-utils).

/etc/cron.daily/testenv-daily:
#!/bin/sh
logger -t testenv-daily "http_proxy=$http_proxy"

/etc/cron.hourly/testenv-hourly:
#!/bin/sh
logger -t testenv-hourly "http_proxy=$http_proxy"

Here are the respective lines of /var/log/syslog:

May 15 09:38:32 wkjpvm6 testenv-daily: http_proxy=
May 15 10:17:01 wkjpvm6 testenv-hourly: http_proxy=http://proxy.krz.uni-heidelberg.de:8080/

I have no idea why the enviroment is set for hourly cron jobs but not for daily cron jobs.

> The cronjob is run from cron; cron is configured via /etc/pam.d/cron to use pam_env.so by default, which reads
 > /etc/environment. Why is this not working on your system?

Same happens also Ubuntu 12.04.4 LTS

Note that this is NOT cron !!!

Date: Tue, 8 Jul 2014 07:48:29 +0300
From: Anacron <root@......fi>
To: root@.......fi

/etc/cron.daily/update-notifier-common:
Traceback (most recent call last):
  File "/usr/lib/update-notifier/package-data-downloader", line 234, in process_download_requests
    dest_file = urllib.urlretrieve(files[i])[0]
  File "/usr/lib/python2.7/urllib.py", line 93, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
  File "/usr/lib/python2.7/urllib.py", line 239, in retrieve
    fp = self.open(url, data)
  File "/usr/lib/python2.7/urllib.py", line 207, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/urllib.py", line 344, in open_http
    h.endheaders(data)
  File "/usr/lib/python2.7/httplib.py", line 954, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python2.7/httplib.py", line 814, in _send_output
    self.send(msg)
  File "/usr/lib/python2.7/httplib.py", line 776, in send
    self.connect()
  File "/usr/lib/python2.7/httplib.py", line 757, in connect
    self.timeout, self.source_address)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
IOError: [Errno socket error] [Errno 101] Network is unreachable
flashplugin-installer: downloading http://archive.canonical.com/pool/partner/a/adobe-flashplugin/adobe-flashplugin_11.2.202.378.orig.tar.gz

See /etc/crontab -- cron does not run these when /usr/sbin/anacron is installed:

# m h dom mon dow user command
17 * * * * root cd / && run-parts --report /etc/cron.hourly
25 6 * * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6 * * 7 root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6 1 * * root test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

/ Kari Hurtta

Marco Gaiarin (marcogaio) wrote :

I confirm this bug, on a 14.04.1 LTS.

I've tried to add:

 # We have to set also proxy. See:
 # https://bugs.launchpad.net/ubuntu/+source/update-notifier/+bug/1317920
 #
 http_proxy="http://proxy:8080/"
 https_proxy="https://proxy:8080/"
 ftp_proxy="ftp://proxy:8080/"

on /etc/anacrontab config file, i hope will fix it.

Marco Gaiarin (marcogaio) wrote :

No, now it raise:

/etc/cron.daily/update-notifier-common:
Traceback (most recent call last):
  File "/usr/lib/update-notifier/package-data-downloader", line 239, in process_download_requests
    dest_file = urllib.urlretrieve(files[i])[0]
  File "/usr/lib/python2.7/urllib.py", line 94, in urlretrieve
    return _urlopener.retrieve(url, filename, reporthook, data)
  File "/usr/lib/python2.7/urllib.py", line 240, in retrieve
    fp = self.open(url, data)
  File "/usr/lib/python2.7/urllib.py", line 203, in open
    return self.open_unknown_proxy(proxy, fullurl, data)
  File "/usr/lib/python2.7/urllib.py", line 222, in open_unknown_proxy
    raise IOError, ('url error', 'invalid proxy for %s' % type, proxy)
IOError: [Errno url error] invalid proxy for http: '"http://proxy:8080/"'

I've tried without quotes (").

Launchpad Janitor (janitor) wrote :

[Expired for update-notifier (Ubuntu) because there has been no activity for 60 days.]

Changed in update-notifier (Ubuntu):
status: Incomplete → Expired
Tharrrk (tharrrk) wrote :

Up.
Confirmed still there on Ubuntu 14.04.1 LTS.

Should we raise the bug for anacron then?

I've set up the transparent proxy locally to avoid this.

Changed in update-notifier (Ubuntu):
status: Expired → Confirmed
affects: update-notifier (Ubuntu) → anacron (Ubuntu)
Changed in update-notifier (Ubuntu):
status: New → Confirmed
Steve Langasek (vorlon) wrote :

> Note that this is NOT cron !!!

> Date: Tue, 8 Jul 2014 07:48:29 +0300
> From: Anacron <root@......fi>
> To: root@.......fi

So this is a problem with anacron, which when run via /etc/cron.d/anacron does not inherit the environment from cron's pam handler (because anacron is run via an upstart job, and upstart jobs always run with a reset environment).

This is therefore a bug in the anacron package.

Changed in update-notifier (Ubuntu):
status: Confirmed → Invalid
Changed in anacron (Ubuntu):
importance: Undecided → High
summary: - update-notifier does not user configured system proxy when downloading
- files with package-data-downloader
+ anacron upstart job does not inherit pam_env config from cron, causes,
+ update-notifier to not use configured system proxy
Changed in anacron (Ubuntu):
status: Confirmed → Triaged
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers