- From: Bryan McLellan <
>
- To:
- Cc: Luke Biddell <
>
- Subject: [chef] Re: apt-get update strategy
- Date: Sun, 27 Mar 2011 06:46:34 -0700
On Fri, Mar 25, 2011 at 2:45 AM, Luke Biddell
<
>
wrote:
>
So what I'd ideally like is to be able to trigger an apt-get update on
>
the first package which requires installing. If no packages require
>
installing, no apt-get update is performed. The fact an update has
>
been performed needs to be recorded as we don't want to do it for
>
every package that's installed as it will kill performance. Once is
>
enough per chef run unless we add/remove a sources.list.d entry (which
>
I already handle using :notifies).
There are a number of strategies. Here's another I used to do.
Only trigger an apt-get update when a repo or key is added, otherwise
rely on Ubuntu to run a daily apt-get update but run it ourselves if
we need to. Note that I was silently rescuing failures as well.
# Run apt-get update to create the stamp file
execute "apt-get-update" do
ignore_failure true
epic_fail true
command "apt-get update"
not_if do File.exists?('/var/lib/apt/periodic/update-success-stamp') end
end
# provides /var/lib/apt/periodic/update-success-stamp on apt-get update
package "update-notifier-common" do
ignore_failure true
notifies :run, resources(:execute => "apt-get-update"), :immediately
end
execute "apt-get-update-periodic" do
ignore_failure true
epic_fail true
command "apt-get update"
only_if do
File.exists?('/var/lib/apt/periodic/update-success-stamp') &&
File.mtime('/var/lib/apt/periodic/update-success-stamp') < Time.now -
86400
end
end
Archive powered by MHonArc 2.6.16.