Initial Chef repository
This commit is contained in:
84
cookbooks/omnibus_updater/CHANGELOG.md
Normal file
84
cookbooks/omnibus_updater/CHANGELOG.md
Normal file
@@ -0,0 +1,84 @@
|
||||
v1.0.4
|
||||
======
|
||||
* file_cache_path path to store chef-client
|
||||
* Avoid deleting chef-server packages if using the same cache dir
|
||||
* Only backup the last old chef client file
|
||||
* make sure directory exists before trying to write to it
|
||||
|
||||
v1.0.2
|
||||
======
|
||||
* Maintenance updates
|
||||
* Support for Fedora
|
||||
* omnitrucker solaris update
|
||||
* bug fixes
|
||||
|
||||
v1.0.0
|
||||
======
|
||||
* Breaking change: `:always_download` is now defaulted to false
|
||||
* Add solaris package install support (#37 thanks @jtimberman)
|
||||
* Update notifies/subscribes usage to support older Chefs (#38 thanks @spheromak)
|
||||
|
||||
v0.2.8
|
||||
======
|
||||
* Always download the package (thanks @miketheman for swiftly pointing out the issue!)
|
||||
|
||||
v0.2.6
|
||||
======
|
||||
* Work with amazon linux (thanks @thommay)
|
||||
* Disable updates on debian 5 (thanks @ianand0204)
|
||||
* Only use major version on debian systems (thanks @kvs)
|
||||
* Allow prevention of downgrades (thanks @buysse)
|
||||
* Add support for restarting chef service after upgrade (thanks @andrewfraley)
|
||||
|
||||
v0.2.4
|
||||
======
|
||||
* Only download omnibus package if version difference detected (#20 #22 #23)
|
||||
* Provide attribute for always downloading package even if version matches
|
||||
|
||||
v0.2.3
|
||||
======
|
||||
* Use chef internals for interactions with omnitruck to provide proper proxy support (#19)
|
||||
|
||||
v0.2.0
|
||||
======
|
||||
* Use omnitruck client for url generation for package fetching
|
||||
* Use `prerelease` in favor of `allow_release_clients`
|
||||
|
||||
v0.1.2
|
||||
======
|
||||
* Fix regression on debian package path construction (thanks [ashmere](https://github.com/ashmere))
|
||||
|
||||
v0.1.1
|
||||
======
|
||||
* Search for proper version suffix if not provided (removes default '-1')
|
||||
* Do not allow release clients by default when version search is enabled
|
||||
* Push omnibus package installation to the end of run (reduces issue described in #10)
|
||||
* Allow updater to be disabled via attribute (thanks [Teemu Matilainen](https://github.com/tmatilai))
|
||||
|
||||
v0.1.0
|
||||
======
|
||||
* Fix redhat related versioning issues
|
||||
* Remove requirement for '-1' suffix on versions
|
||||
* Initial support for automatic latest version install
|
||||
|
||||
v0.0.5
|
||||
======
|
||||
* Add support for Ubuntu 12.10
|
||||
* Path fixes for non-64 bit packages (thanks [ashmere](https://github.com/ashmere))
|
||||
|
||||
v0.0.4
|
||||
======
|
||||
* Use new aws bucket by default
|
||||
* Update file key building
|
||||
|
||||
v0.0.3
|
||||
======
|
||||
* Path fix for debian omnibus packages (thanks [ashmere](https://github.com/ashmere))
|
||||
|
||||
v0.0.2
|
||||
======
|
||||
* Add robust check when uninstalling chef gem to prevent removal from omnibus
|
||||
|
||||
v0.0.1
|
||||
======
|
||||
* Initial release
|
||||
88
cookbooks/omnibus_updater/README.md
Normal file
88
cookbooks/omnibus_updater/README.md
Normal file
@@ -0,0 +1,88 @@
|
||||
OmnibusUpdater
|
||||
==============
|
||||
|
||||
Update your omnibus! This cookbook can install the omnibus
|
||||
Chef package into your system if you are currently running
|
||||
via gem install, and it can keep your omnibus install up
|
||||
to date.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
Add the recipe to your run list and specify what version should
|
||||
be installed on the node:
|
||||
|
||||
`knife node run_list add recipe[omnibus_updater]`
|
||||
|
||||
In your role you'll likely want to set the version. It defaults
|
||||
to nothing, and will install the latest..
|
||||
|
||||
```
|
||||
override_attributes(
|
||||
:omnibus_updater => {
|
||||
:version => '11.4.0'
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
It can also uninstall Chef from the system Ruby installation
|
||||
if you tell it to:
|
||||
|
||||
```
|
||||
override_attributes(
|
||||
:omnibus_updater => {
|
||||
:remove_chef_system_gem => true
|
||||
}
|
||||
)
|
||||
```
|
||||
|
||||
Features
|
||||
========
|
||||
|
||||
Latest Version
|
||||
--------------
|
||||
|
||||
Force installation of the latest version regardless of value stored in version
|
||||
attribute by setting the `force_latest` attribute.
|
||||
|
||||
Chef Killing
|
||||
------------
|
||||
|
||||
By default the omnibus updater will kill the chef instance by raising an exception.
|
||||
You can turn this off using the `kill_chef_on_upgrade` attribute. It is not
|
||||
recommended to turn this off. Internal chef libraries may change, move, or no
|
||||
longer exist. The currently running instance can encounter unexpected states because
|
||||
of this. To prevent this, the updater will attempt to kill the Chef instance so
|
||||
that it can be restarted in a normal state.
|
||||
|
||||
Restart chef-client Service
|
||||
---------------------------
|
||||
|
||||
Use the `restart_chef_service` attribute to restart chef-client if you have it running as a service.
|
||||
|
||||
Prerelease
|
||||
--------
|
||||
|
||||
Prereleases can be installed via the auto-installation using `prerelease` attribute.
|
||||
|
||||
Disable
|
||||
-------
|
||||
|
||||
If you want to disable the updater you can set the `disabled`
|
||||
attribute to true. This might be useful if the cookbook is added
|
||||
to a role but should then be skipped for example on a Chef server.
|
||||
|
||||
Prevent Downgrade
|
||||
-----------------
|
||||
|
||||
If you want to prevent the updater from downgrading chef on a node, you
|
||||
can set the `prevent_downgrade` attribute to true. This can be useful
|
||||
for testing new versions manually. Note that the `always_download`
|
||||
attribute takes precedence if set.
|
||||
|
||||
Infos
|
||||
=====
|
||||
|
||||
* Repo: https://github.com/hw-cookbooks/omnibus_updater
|
||||
* IRC: Freenode @ #heavywater
|
||||
* Cookbook: http://ckbk.it/omnibus_updater
|
||||
31
cookbooks/omnibus_updater/attributes/default.rb
Normal file
31
cookbooks/omnibus_updater/attributes/default.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# Cookbook Name:: omnibus_updater
|
||||
# Attributes:: default
|
||||
#
|
||||
# Copyright 2014, Heavy Water Ops, LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
default[:omnibus_updater][:version] = nil
|
||||
default[:omnibus_updater][:force_latest] = false
|
||||
default[:omnibus_updater][:cache_dir] = "#{Chef::Config[:file_cache_path]}/omnibus_updater"
|
||||
default[:omnibus_updater][:cache_omnibus_installer] = false
|
||||
default[:omnibus_updater][:remove_chef_system_gem] = false
|
||||
default[:omnibus_updater][:prerelease] = false
|
||||
default[:omnibus_updater][:disabled] = false
|
||||
default[:omnibus_updater][:kill_chef_on_upgrade] = true
|
||||
default[:omnibus_updater][:always_download] = false
|
||||
default[:omnibus_updater][:prevent_downgrade] = false
|
||||
default[:omnibus_updater][:restart_chef_service] = false
|
||||
default[:omnibus_updater][:checksum] = nil
|
||||
30
cookbooks/omnibus_updater/libraries/omnibus_checker.rb
Normal file
30
cookbooks/omnibus_updater/libraries/omnibus_checker.rb
Normal file
@@ -0,0 +1,30 @@
|
||||
#
|
||||
# Cookbook Name:: omnibus_updater
|
||||
# Library:: omnibuschecker
|
||||
#
|
||||
# Copyright 2014, Heavy Water Ops, LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
module OmnibusChecker
|
||||
def is_omnibus?
|
||||
Gem.bindir =~ %r{/opt/(opscode|chef)/}
|
||||
end
|
||||
end
|
||||
|
||||
OmnibusChecker.send(:extend, OmnibusChecker)
|
||||
|
||||
unless(Chef::Recipe.instance_methods.include?(:is_omnibus?))
|
||||
Chef::Recipe.send(:include, OmnibusChecker)
|
||||
end
|
||||
92
cookbooks/omnibus_updater/libraries/omnitrucker.rb
Normal file
92
cookbooks/omnibus_updater/libraries/omnitrucker.rb
Normal file
@@ -0,0 +1,92 @@
|
||||
#
|
||||
# Cookbook Name:: omnibus_updater
|
||||
# Library:: omnitrucker
|
||||
#
|
||||
# Copyright 2014, Heavy Water Ops, LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
module OmnibusTrucker
|
||||
class << self
|
||||
URL_MAP = {
|
||||
:p => :platform, :pv => :platform_version, :m => :machine,
|
||||
:v => :version, :prerelease => :prerelease,
|
||||
:nightlies => :nightlies
|
||||
}
|
||||
|
||||
def build_url(*opts)
|
||||
args = node = nil
|
||||
opts.each do |o|
|
||||
if(o.kind_of?(Hash))
|
||||
args = o
|
||||
elsif(o.kind_of?(Chef::Node))
|
||||
node = o
|
||||
else
|
||||
raise ArgumentError.new "Provided argument is not allowed: #{o.class}"
|
||||
end
|
||||
end
|
||||
args ||= {}
|
||||
if(node)
|
||||
args = collect_attributes(node).merge(args)
|
||||
end
|
||||
url = args[:url] || "http://www.opscode.com/chef/download#{'-server' if args[:server]}"
|
||||
u_args = URL_MAP.map do |u_k, a_k|
|
||||
"#{u_k}=#{args[a_k]}" unless args[a_k].nil?
|
||||
end.compact
|
||||
"#{url}?#{u_args.join('&')}"
|
||||
end
|
||||
|
||||
def collect_attributes(node, args={})
|
||||
set = Mash[
|
||||
[:platform_family, :platform, :platform_version].map do |k|
|
||||
[k, args[k] || node[k]]
|
||||
end
|
||||
]
|
||||
unless(@attrs)
|
||||
if(set[:platform] == 'amazon')
|
||||
@attrs = {:platform => 'el', :platform_version => 6}
|
||||
elsif(set[:platform_family] == 'fedora')
|
||||
@attrs = {:platform => 'el', :platform_version => 6}
|
||||
elsif(set[:platform_family] == 'rhel')
|
||||
@attrs = {:platform => 'el', :platform_version => set[:platform_version].to_i}
|
||||
elsif(set[:platform] == 'debian')
|
||||
@attrs = {:platform => set[:platform], :platform_version => set[:platform_version].to_i}
|
||||
elsif(set[:platform_family] == 'mac_os_x')
|
||||
@attrs = {:platform => set[:platform_family], :platform_version => [set[:platform_version].to_f, 10.7].min}
|
||||
else
|
||||
@attrs = {:platform => set[:platform], :platform_version => set[:platform_version]}
|
||||
end
|
||||
@attrs[:machine] = args[:machine] || node[:kernel][:machine]
|
||||
@attrs[:machine] = "i386" if(set[:platform_family] == 'solaris2' && @attrs[:machine] == "i86pc")
|
||||
end
|
||||
@attrs
|
||||
end
|
||||
|
||||
def url(url_or_node, node = nil)
|
||||
if(url_or_node.is_a?(Chef::Node))
|
||||
url = build_url(url_or_node)
|
||||
node = url_or_node
|
||||
else
|
||||
url = url_or_node
|
||||
raise "Node instance is required for Omnitruck.url!" unless node
|
||||
end
|
||||
request = Chef::REST::RESTRequest.new(:head, URI.parse(url), nil)
|
||||
result = request.call
|
||||
if(result.kind_of?(Net::HTTPRedirection))
|
||||
result['location']
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
29
cookbooks/omnibus_updater/metadata.json
Normal file
29
cookbooks/omnibus_updater/metadata.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "omnibus_updater",
|
||||
"description": "Chef omnibus package updater and installer",
|
||||
"long_description": "OmnibusUpdater\n==============\n\nUpdate your omnibus! This cookbook can install the omnibus\nChef package into your system if you are currently running\nvia gem install, and it can keep your omnibus install up\nto date.\n\nUsage\n=====\n\nAdd the recipe to your run list and specify what version should\nbe installed on the node:\n\n`knife node run_list add recipe[omnibus_updater]`\n\nIn your role you'll likely want to set the version. It defaults\nto nothing, and will install the latest..\n\n```\noverride_attributes(\n :omnibus_updater => {\n :version => '11.4.0'\n }\n)\n```\n\nIt can also uninstall Chef from the system Ruby installation\nif you tell it to:\n\n```\noverride_attributes(\n :omnibus_updater => {\n :remove_chef_system_gem => true\n }\n)\n```\n\nFeatures\n========\n\nLatest Version\n--------------\n\nForce installation of the latest version regardless of value stored in version\nattribute by setting the `force_latest` attribute.\n\nChef Killing\n------------\n\nBy default the omnibus updater will kill the chef instance by raising an exception.\nYou can turn this off using the `kill_chef_on_upgrade` attribute. It is not\nrecommended to turn this off. Internal chef libraries may change, move, or no\nlonger exist. The currently running instance can encounter unexpected states because\nof this. To prevent this, the updater will attempt to kill the Chef instance so\nthat it can be restarted in a normal state.\n\nRestart chef-client Service\n---------------------------\n\nUse the `restart_chef_service` attribute to restart chef-client if you have it running as a service.\n\nPrerelease\n--------\n\nPrereleases can be installed via the auto-installation using `prerelease` attribute.\n\nDisable\n-------\n\nIf you want to disable the updater you can set the `disabled`\nattribute to true. This might be useful if the cookbook is added\nto a role but should then be skipped for example on a Chef server.\n\nPrevent Downgrade\n-----------------\n\nIf you want to prevent the updater from downgrading chef on a node, you \ncan set the `prevent_downgrade` attribute to true. This can be useful\nfor testing new versions manually. Note that the `always_download` \nattribute takes precedence if set.\n\nInfos\n=====\n\n* Repo: https://github.com/hw-cookbooks/omnibus_updater\n* IRC: Freenode @ #heavywater\n* Cookbook: http://ckbk.it/omnibus_updater\n",
|
||||
"maintainer": "Chris Roberts",
|
||||
"maintainer_email": "chrisroberts.code@gmail.com",
|
||||
"license": "Apache 2.0",
|
||||
"platforms": {
|
||||
},
|
||||
"dependencies": {
|
||||
},
|
||||
"recommendations": {
|
||||
},
|
||||
"suggestions": {
|
||||
},
|
||||
"conflicting": {
|
||||
},
|
||||
"providing": {
|
||||
},
|
||||
"replacing": {
|
||||
},
|
||||
"attributes": {
|
||||
},
|
||||
"groupings": {
|
||||
},
|
||||
"recipes": {
|
||||
},
|
||||
"version": "1.0.4"
|
||||
}
|
||||
7
cookbooks/omnibus_updater/metadata.rb
Normal file
7
cookbooks/omnibus_updater/metadata.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
name "omnibus_updater"
|
||||
maintainer "Chris Roberts"
|
||||
maintainer_email "chrisroberts.code@gmail.com"
|
||||
license "Apache 2.0"
|
||||
description "Chef omnibus package updater and installer"
|
||||
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
|
||||
version "1.0.4"
|
||||
31
cookbooks/omnibus_updater/recipes/default.rb
Normal file
31
cookbooks/omnibus_updater/recipes/default.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
#
|
||||
# Cookbook Name:: omnibus_updater
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2014, Heavy Water Ops, LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
if(node[:omnibus_updater][:disabled])
|
||||
Chef::Log.warn 'Omnibus updater disabled via `disabled` attribute'
|
||||
elsif(node[:platform] == 'debian' && Gem::Version.new(node[:platform_version]) < Gem::Version.new('6.0.0'))
|
||||
Chef::Log.warn 'Omnibus updater does not support Debian 5'
|
||||
else
|
||||
include_recipe 'omnibus_updater::downloader'
|
||||
include_recipe 'omnibus_updater::installer'
|
||||
end
|
||||
|
||||
if(node[:omnibus_updater][:remove_chef_system_gem])
|
||||
include_recipe 'omnibus_updater::remove_chef_system_gem'
|
||||
end
|
||||
71
cookbooks/omnibus_updater/recipes/downloader.rb
Normal file
71
cookbooks/omnibus_updater/recipes/downloader.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
#
|
||||
# Cookbook Name:: omnibus_updater
|
||||
# Recipe:: downloader
|
||||
#
|
||||
# Copyright 2014, Heavy Water Ops, LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# NOTE: This recipe is here for others that just want the
|
||||
# package, not the actual installation (lxc for example)
|
||||
|
||||
if(node[:omnibus_updater][:direct_url])
|
||||
remote_path = node[:omnibus_updater][:direct_url]
|
||||
else
|
||||
version = node[:omnibus_updater][:version] || ''
|
||||
remote_path = OmnibusTrucker.url(
|
||||
OmnibusTrucker.build_url(node,
|
||||
:version => node[:omnibus_updater][:force_latest] ? nil : version.sub(/\-.+$/, ''),
|
||||
:prerelease => node[:omnibus_updater][:preview]
|
||||
), node
|
||||
)
|
||||
end
|
||||
|
||||
if(remote_path)
|
||||
node.set[:omnibus_updater][:full_url] = remote_path
|
||||
|
||||
directory node[:omnibus_updater][:cache_dir] do
|
||||
recursive true
|
||||
end
|
||||
|
||||
remote_file "omnibus_remote[#{File.basename(remote_path)}]" do
|
||||
path File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))
|
||||
source remote_path
|
||||
backup false
|
||||
checksum node[:omnibus_updater][:checksum] if node[:omnibus_updater][:checksum]
|
||||
action :create_if_missing
|
||||
only_if do
|
||||
unless(version = node[:omnibus_updater][:version])
|
||||
version = node[:omnibus_updater][:full_url].scan(%r{chef[_-](\d+\.\d+.\d+)}).flatten.first
|
||||
end
|
||||
if(node[:omnibus_updater][:always_download])
|
||||
# warn if there may be unexpected behavior
|
||||
node[:omnibus_updater][:prevent_downgrade] &&
|
||||
Chef::Log.warn("omnibus_updater: prevent_downgrade is ignored when always_download is true")
|
||||
Chef::Log.debug "Omnibus Updater remote path: #{remote_path}"
|
||||
true
|
||||
elsif(node[:omnibus_updater][:prevent_downgrade])
|
||||
# Return true if the found/specified version is newer
|
||||
Gem::Version.new(version.to_s.sub(/\-.+$/, '')) > Gem::Version.new(Chef::VERSION)
|
||||
else
|
||||
# default is to install if the versions don't match
|
||||
Chef::VERSION != version.to_s.sub(/\-.+$/, '')
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
Chef::Log.warn 'Failed to retrieve omnibus download URL'
|
||||
end
|
||||
|
||||
include_recipe 'omnibus_updater::old_package_cleaner'
|
||||
70
cookbooks/omnibus_updater/recipes/installer.rb
Normal file
70
cookbooks/omnibus_updater/recipes/installer.rb
Normal file
@@ -0,0 +1,70 @@
|
||||
#
|
||||
# Cookbook Name:: omnibus_updater
|
||||
# Recipe:: installer
|
||||
#
|
||||
# Copyright 2014, Heavy Water Ops, LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe 'omnibus_updater'
|
||||
remote_path = node[:omnibus_updater][:full_url].to_s
|
||||
|
||||
file '/tmp/nocheck' do
|
||||
content 'conflict=nocheck\naction=nocheck'
|
||||
only_if { node['os'] =~ /^solaris/ }
|
||||
end
|
||||
|
||||
service 'chef-client' do
|
||||
action :nothing
|
||||
end
|
||||
|
||||
ruby_block 'omnibus chef killer' do
|
||||
block do
|
||||
raise 'New omnibus chef version installed. Killing Chef run!'
|
||||
end
|
||||
action :nothing
|
||||
only_if do
|
||||
node[:omnibus_updater][:kill_chef_on_upgrade]
|
||||
end
|
||||
end
|
||||
|
||||
execute "omnibus_install[#{File.basename(remote_path)}]" do
|
||||
case File.extname(remote_path)
|
||||
when '.deb'
|
||||
command "dpkg -i #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}"
|
||||
when '.rpm'
|
||||
command "rpm -Uvh --oldpackage #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}"
|
||||
when '.sh'
|
||||
command "/bin/sh #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))}"
|
||||
when '.solaris'
|
||||
command "pkgadd -n -d #{File.join(node[:omnibus_updater][:cache_dir], File.basename(remote_path))} -a /tmp/nocheck chef"
|
||||
else
|
||||
raise "Unknown package type encountered for install: #{File.extname(remote_path)}"
|
||||
end
|
||||
action :nothing
|
||||
if(node[:omnibus_updater][:restart_chef_service])
|
||||
notifies :restart, resources(:service => 'chef-client'), :immediately
|
||||
end
|
||||
notifies :create, resources(:ruby_block => 'omnibus chef killer'), :immediately
|
||||
end
|
||||
|
||||
ruby_block 'Omnibus Chef install notifier' do
|
||||
block{ true }
|
||||
action :nothing
|
||||
subscribes :create, resources(:remote_file => "omnibus_remote[#{File.basename(remote_path)}]"), :immediately
|
||||
notifies :run, resources(:execute => "omnibus_install[#{File.basename(remote_path)}]"), :delayed
|
||||
only_if { node['chef_packages']['chef']['version'] != node['omnibus_updater']['version'] }
|
||||
end
|
||||
|
||||
include_recipe 'omnibus_updater::old_package_cleaner'
|
||||
34
cookbooks/omnibus_updater/recipes/old_package_cleaner.rb
Normal file
34
cookbooks/omnibus_updater/recipes/old_package_cleaner.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
#
|
||||
# Cookbook Name:: omnibus_updater
|
||||
# Recipe:: old_package_cleaner
|
||||
#
|
||||
# Copyright 2014, Heavy Water Ops, LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
old_pkgs =
|
||||
if(::File.exist?(node[:omnibus_updater][:cache_dir]))
|
||||
Dir.glob(File.join(node[:omnibus_updater][:cache_dir], 'chef_*')).find_all do |file|
|
||||
!file.include?(node[:omnibus_updater][:version].to_s) && !file.scan(/\.(rpm|deb)$/).empty?
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
|
||||
old_pkgs.each do |filename|
|
||||
file filename do
|
||||
action :delete
|
||||
backup 1
|
||||
end
|
||||
end
|
||||
29
cookbooks/omnibus_updater/recipes/remove_chef_system_gem.rb
Normal file
29
cookbooks/omnibus_updater/recipes/remove_chef_system_gem.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
#
|
||||
# Cookbook Name:: omnibus_updater
|
||||
# Recipe:: remove_chef_system_gem
|
||||
#
|
||||
# Copyright 2014, Heavy Water Ops, LLC
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
gem_package 'chef' do
|
||||
action :purge
|
||||
only_if do
|
||||
Chef::Provider::Package::Rubygems.new(
|
||||
Chef::Resource::GemPackage.new('dummy_package')
|
||||
).gem_env.gem_paths.detect{|path|
|
||||
path.start_with?('/opt/omnibus') || path.start_with?('/opt/chef')
|
||||
}.nil? && node[:omnibus_updater][:remove_chef_system_gem]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user