Replace omnibus_updater with chef_client_updater

omnibus_updater is deprecated
This commit is contained in:
Greg Karékinian
2017-05-02 11:53:33 +02:00
parent 030b2501eb
commit 943b4ace1f
23 changed files with 285 additions and 677 deletions

View File

@@ -0,0 +1 @@
~FC016

View File

@@ -0,0 +1,16 @@
# chef_client_updater Cookbook CHANGELOG
This file is used to list changes made in each version of the chef_client_updater cookbook.
## 1.0.2 (2017-04-07)
- Fix Chef 13 compatibility by using Kernel.exec not exec
## 1.0.1 (2017-04-07)
- point the URLs at the new project repo
- Add ChefSpec matcher
## 1.0.0
- Initial release of chef_client_updater

View File

@@ -0,0 +1 @@
Please refer to <https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD>

View File

@@ -0,0 +1,15 @@
<!-- This is a generated file. Please do not edit directly -->
# Maintainers
This file lists how this cookbook project is maintained. When making changes to the system, this file tells you who needs to review your patch - you need a review from an existing maintainer for the cookbook to provide a :+1: on your pull request. Additionally, you need to not receive a veto from a Lieutenant or the Project Lead.
Check out [How Cookbooks are Maintained](https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/CONTRIBUTING.MD) for details on the process and how to become a maintainer or the project lead.
# Project Maintainer
* [Tim Smith](https://github.com/tas50)
# Maintainers
* [Jennifer Davis](https://github.com/sigje)
* [Tim Smith](https://github.com/tas50)
* [Thom May](https://github.com/thommay)

View File

@@ -0,0 +1,69 @@
# chef_client_updater
[![Build Status](https://travis-ci.org/chef-cookbooks/chef_client_updater.svg?branch=master)](https://travis-ci.org/chef-cookbooks/chef_client_updater) [![Cookbook Version](https://img.shields.io/cookbook/v/chef_client_updater.svg)](https://supermarket.chef.io/cookbooks/chef_client_updater)
This cookbook updates the chef-client
## Requirements
### Platforms
- All platforms with a chef-client package on downloads.chef.io
### Chef
- Chef 12.1+
### Cookbooks
- compat_resource
### Usage
This cookbook provides both a custom resource and a default recipe. The default recipe simply uses the custom resource with a set of attributes. You can add chef_client_updater::default to your run list or use the custom resource in a wrapper cookbook.
### chef_client_updater
Installs the mixlib-install/mixlib-install gems and upgrades the chef-client.
#### properties
- `channel` - The chef channel you fetch the chef client from. `stable` contains all officially released chef-client builds where as `current` contains unreleased builds. Default: `stable`
- `prevent_downgrade` - Don't allow this cookbook to downgrade the chef-client version. Default: true
- `version` - The version of the chef-client to install. Default :latest
- `post_install_action` - After installing the chef-client what should we do. `exec` to exec the new client or `kill` to kill the client and rely on the init system to start up the new version. Default: `exec`
- `exec_command` - The chef-client command. default: $PROGRAM_NAME.split(' ').first
- `exec_args` - An array of arguments to exec the chef-client with. default: ARGV
#### examples
```ruby
chef_client_updater 'Install latest'
```
```ruby
chef_client_updater 'Install 12.13.36 and kill' do
version '12.13.36'
post_install_action 'kill'
end
```
## License & Authors
- Author: Tim Smith ([tsmith@chef.io](mailto:tsmith@chef.io))
```text
Copyright:: 2016-2017, Chef Software, Inc
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.
```

View File

@@ -0,0 +1,29 @@
#
# Cookbook:: chef_client_updater
# Attributes:: default
#
# Copyright:: 2016-2017, Chef Software, Inc.
#
# 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.
# stable or current channel
default['chef_client_updater']['channel'] = 'stable'
# prevent a newer client "updating" to an older client
default['chef_client_updater']['prevent_downgrade'] = true
# the version to install (ex: '12.12.13') or 'latest'
default['chef_client_updater']['version'] = 'latest'
# kill the client post install or exec the client post install for non-service based installs
default['chef_client_updater']['post_install_action'] = 'kill'

View File

@@ -0,0 +1,7 @@
if defined?(ChefSpec)
ChefSpec.define_matcher(:chef_client_updater)
def update_chef_client_updater(resource_name)
ChefSpec::Matchers::ResourceMatcher.new(:chef_client_updater, :update, resource_name)
end
end

View File

@@ -0,0 +1 @@
{"name":"chef_client_updater","version":"1.0.2","description":"Upgrades chef-client to specified releases","long_description":"Upgrades chef-client to specified releases","maintainer":"Chef Software, Inc.","maintainer_email":"cookbooks@chef.io","license":"Apache-2.0","platforms":{"amazon":">= 0.0.0","centos":">= 0.0.0","debian":">= 0.0.0","mac_os_x":">= 0.0.0","opensuse":">= 0.0.0","opensuseleap":">= 0.0.0","oracle":">= 0.0.0","redhat":">= 0.0.0","scientific":">= 0.0.0","solaris":">= 0.0.0","suse":">= 0.0.0","ubuntu":">= 0.0.0","windows":">= 0.0.0","aix":">= 0.0.0"},"dependencies":{"compat_resource":">= 12.16.3"},"recommendations":{},"suggestions":{},"conflicting":{},"providing":{},"replacing":{},"attributes":{},"groupings":{},"recipes":{},"source_url":"https://github.com/chef-cookbooks/chef_client_updater","issues_url":"https://github.com/chef-cookbooks/chef_client_updater/issues","chef_version":[[">= 12.1"]],"ohai_version":[]}

View File

@@ -0,0 +1,25 @@
#
# Author:: Tim Smith (<tsmith@chef.io>)
# Cookbook:: chef_client_updater
# Recipe:: default
#
# Copyright:: 2016-2017, Chef Software, Inc.
#
# 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.
chef_client_updater 'update chef-client' do
channel node['chef_client_updater']['channel']
version node['chef_client_updater']['version']
prevent_downgrade node['chef_client_updater']['prevent_downgrade']
post_install_action node['chef_client_updater']['post_install_action']
end

View File

@@ -0,0 +1,136 @@
#
# Cookbook:: chef_client_updater
# Resource:: updater
#
# Copyright:: 2016-2017, Will Jordan
# Copyright:: 2016-2017, Chef Software, Inc.
#
# 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.
#
provides 'chef_client_updater'
property :channel, [String, Symbol], default: :stable
property :prevent_downgrade, [true, false], default: false
property :version, [String, Symbol], default: :latest
property :post_install_action, String, default: 'exec'
property :exec_command, String, default: $PROGRAM_NAME.split(' ').first
property :exec_args, Array, default: ARGV
action :update do
if update_necessary? # ~FC023
converge_by "Upgraded chef-client #{current_version} to #{desired_version}" do
upgrade_command = Mixlib::ShellOut.new(mixlib_install.install_command)
upgrade_command.run_command
run_post_install_action
end
end
end
action_class.class_eval do
def load_mixlib_install
require 'mixlib/install'
rescue LoadError
Chef::Log.info('mixlib-install gem not found. Installing now')
chef_gem 'mixlib-install' do
compile_time true if respond_to?(:compile_time)
end
require 'mixlib/install'
end
def load_mixlib_versioning
require 'mixlib/versioning'
rescue LoadError
Chef::Log.info('mixlib-versioning gem not found. Installing now')
chef_gem 'mixlib-versioning' do
compile_time true if respond_to?(:compile_time)
end
require 'mixlib/versioning'
end
def mixlib_install
load_mixlib_install
options = {
product_name: 'chef',
platform_version_compatibility_mode: true,
channel: new_resource.channel.to_sym,
product_version: new_resource.version == 'latest' ? :latest : new_resource.version,
}
Mixlib::Install.new(options)
end
# why would we use this when mixlib-install has a current_version method?
# well mixlib-version parses the manifest JSON, which might not be there.
# ohai handles this better IMO
def current_version
node['chef_packages']['chef']['version']
end
def desired_version
new_resource.version == 'latest' ? mixlib_install.available_versions.last : new_resource.version
end
# why wouldn't we use the built in update_available? method in mixlib-install?
# well that would use current_version from mixlib-install and it has no
# concept or preventing downgrades
def update_necessary?
load_mixlib_versioning
cur_version = Mixlib::Versioning.parse(current_version)
des_version = Mixlib::Versioning.parse(desired_version)
new_resource.prevent_downgrade ? (des_version > cur_version) : (des_version != cur_version)
end
def eval_post_install_action
return unless new_resource.post_install_action == 'exec'
if Chef::Config[:interval]
Chef::Log.warn 'post_install_action "exec" not supported for long-running client process -- changing to "kill".'
new_resource.post_install_action = 'kill'
end
return if Process.respond_to?(:exec)
Chef::Log.warn 'post_install_action Process.exec not available -- changing to "kill".'
new_resource.post_install_action = 'kill'
end
def run_post_install_action
# make sure the passed action will actually work
eval_post_install_action
case new_resource.post_install_action
when 'exec'
if Chef::Config[:local_mode]
Chef::Log.info 'Shutting down local-mode server.'
if Chef::Application.respond_to?(:destroy_server_connectivity)
Chef::Application.destroy_server_connectivity
elsif defined?(Chef::LocalMode) && Chef::LocalMode.respond_to?(:destroy_server_connectivity)
Chef::LocalMode.destroy_server_connectivity
end
end
Chef::Log.warn 'Replacing ourselves with the new version of Chef to continue the run.'
Kernel.exec(new_resource.exec_command, *new_resource.exec_args)
when 'kill'
if Chef::Config[:client_fork] && Process.ppid != 1
Chef::Log.warn 'Chef client is defined for forked runs. Sending TERM to parent process!'
Process.kill('TERM', Process.ppid)
end
Chef::Log.warn 'New chef-client installed. Forcing chef exit!'
exit(213)
else
raise "Unexpected post_install_action behavior: #{new_resource.post_install_action}"
end
end
end