Skip to content

Commit

Permalink
More chef-client / chef -> Chef Infra Client
Browse files Browse the repository at this point in the history
Marketing rules everything around us

Signed-off-by: Tim Smith <[email protected]>
  • Loading branch information
tas50 committed May 27, 2020
1 parent 2a9cfc0 commit 03ac509
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 26 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Installs the mixlib-install/mixlib-install gems and upgrades the Chef Infra Clie
- `install_timeout` - The install timeout for non-windows systems. The default is 600, slow machines may need to extend this.
- `upgrade_delay` - The delay in seconds before the scheduled task to upgrade Chef Infra Client runs on windows. default: 61. Lowering this limit is not recommended.
- `product_name` - The name of the product to upgrade. This can be `chef` or `chefdk` default: chef
- 'install_command_options' - A Hash of additional options that will be passed to the Mixlib::Install instance responsible for installing the given product_name. To install Chef Infra Client as a scheduled task on windows, one can pass {daemon: 'task'}. Default: {}
- 'install_command_options' - A Hash of additional options that will be passed to the Mixlib::Install instance responsible for installing the given product_name. To install Chef Infra Client as a scheduled task on windows, one can pass {daemon: 'task'}. Default: {}
- `rubygems_url` - The location to source rubygems. Replaces the default https://www.rubygems.org.
- `handle_zip_download_url` - Url to the Handle zip archive used by Windows. Used to override the default in airgapped environments. default: https://download.sysinternals.com/files/Handle.zip (Note that you can also override the `default['chef_client_updater']['handle_exe_path']` attribute if you already have that binary somewhere on your system)

Expand Down Expand Up @@ -141,8 +141,7 @@ You can use 'exec' in production if you are running from cron or some other proc

## A note about purpose

While this cookbook supports running on Chef Infra Client versions back to 11/12, the supported behavior of the cookbook is to upgrade those versions to 13/14 or newer. It is not intended that users would maintain old Chef-11/12 versions with this
cookbook. The latest released version of Chef Infra Client 12 (12.22.1 or later) is still be supported as a target. Older versions of Chef Infra Client will have their embedded rubygems force upgraded by this cookbook to avoid having to regression test against 5+ years of rubygems bugs and establish a stable basis for the cookbook to use.
While this cookbook supports running on Chef Infra Client versions back to 11/12, the supported behavior of the cookbook is to upgrade those versions to 13/14 or newer. It is not intended that users would maintain old Chef-11/12 versions with this cookbook. The latest released version of Chef Infra Client 12 (12.22.1 or later) is still be supported as a target. Older versions of Chef Infra Client will have their embedded rubygems force upgraded by this cookbook to avoid having to regression test against 5+ years of rubygems bugs and establish a stable basis for the cookbook to use.

## License

Expand Down
6 changes: 3 additions & 3 deletions attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Cookbook:: chef_client_updater
# Cookbook:: chef_client_updater
# Attributes:: default
#
# Copyright:: 2016-2018, Chef Software Inc.
# Copyright:: 2016-2020, 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.
Expand Down Expand Up @@ -38,7 +38,7 @@
# Defaults to 'C:/opscode/chef' on Windows and '/opt/chef' for everything else.
default['chef_client_updater']['chef_install_path'] = nil

# delay for triggering Chef client upgrade in seconds
# delay for triggering Chef Infra Client upgrade in seconds
default['chef_client_updater']['upgrade_delay'] = nil

# name of the product to upgrade (chef or chefdk)
Expand Down
32 changes: 16 additions & 16 deletions providers/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

# NOTE: this cookbook uses Chef-11 backwards compatible syntax to support
# upgrades from Chef 11.x and this pattern should not be copied for any modern
# cookbook. This is a poor example cookbook of how to write Chef.
# cookbook. This is a poor example cookbook of how to write Chef Infra code.

include ::ChefClientUpdaterHelper

Expand Down Expand Up @@ -81,7 +81,7 @@ def update_rubygems
if new_resource.rubygems_url
gem_bin = "#{Gem.bindir}/gem"
if !::File.exist?(gem_bin) && windows?
gem_bin = "#{Gem.bindir}/gem.cmd" # on Chef Client 13+ the rubygem executable is gem.cmd, not gem
gem_bin = "#{Gem.bindir}/gem.cmd" # on Chef Infra Client 13+ the rubygem executable is gem.cmd, not gem
end
raise 'cannot find omnibus install' unless ::File.exist?(gem_bin)
source = "--clear-sources --source #{new_resource.rubygems_url}"
Expand Down Expand Up @@ -163,7 +163,7 @@ def update_necessary?
cur_version = Mixlib::Versioning.parse(current_version)
Chef::Log.debug("The current #{new_resource.product_name} version is #{cur_version} and the desired version is #{des_version}")
necessary = new_resource.prevent_downgrade ? (des_version > cur_version) : (des_version != cur_version)
Chef::Log.debug("A chef-client upgrade #{necessary ? 'is' : "isn't"} necessary")
Chef::Log.debug("A Chef Infra Client upgrade #{necessary ? 'is' : "isn't"} necessary")
necessary
end
end
Expand All @@ -172,7 +172,7 @@ def eval_post_install_action
return unless new_resource.post_install_action == 'exec'

if Chef::Config[:interval] || Chef::Config[:client_fork]
Chef::Log.warn 'post_install_action "exec" not supported for chef-client running forked -- changing to "kill".'
Chef::Log.warn 'post_install_action "exec" not supported for Chef Infra Client running forked -- changing to "kill".'
new_resource.post_install_action = 'kill'
end

Expand Down Expand Up @@ -207,7 +207,7 @@ def run_post_install_action
Chef::Log.warn 'Chef client is running forked with a supervisor. Sending KILL to parent process!'
Process.kill('KILL', Process.ppid)
end
Chef::Log.warn 'New chef-client installed and exit is allowed. Forcing chef exit!'
Chef::Log.warn 'New Chef Infra Client installed and exit is allowed. Forcing Chef Infra Client exit!'
exit(213)
else
raise "Unexpected post_install_action behavior: #{new_resource.post_install_action}"
Expand All @@ -233,17 +233,17 @@ def chef_upgrade_log
# cleanup cruft from *prior* runs
def cleanup
if ::File.exist?(chef_backup_dir)
converge_by("remove #{chef_backup_dir} from previous chef-client run") do
converge_by("remove #{chef_backup_dir} from previous Chef Infra Client run") do
FileUtils.rm_rf chef_backup_dir
end
end
if ::File.exist?(chef_upgrade_log)
converge_by("remove #{chef_upgrade_log} from previous chef-client run") do
converge_by("remove #{chef_upgrade_log} from previous Chef Infra Client run") do
FileUtils.rm_rf chef_upgrade_log
end
end
if ::File.exist?(chef_broken_dir) && new_resource.event_log_service_restart
converge_by("remove #{chef_broken_dir} from previous chef-client run") do
converge_by("remove #{chef_broken_dir} from previous Chef Infra Client run") do
event_log_ps_code
FileUtils.rm_rf chef_broken_dir
end
Expand All @@ -266,7 +266,7 @@ def copy_opt_chef(src, dest)
end

# windows does not like having running open files nuked behind it so we have to move the old file
# out of the way. on both platforms we must clean up the old install to not leave behind any old
# out of the way. on both platforms we must clean up the old install to not leave behind any old
# gem files.
#
def move_opt_chef(src, dest)
Expand Down Expand Up @@ -342,7 +342,7 @@ def uninstall_ps_code
def wait_for_chef_client_or_reschedule_upgrade_task_function
<<-EOH
Function WaitForChefClientOrRescheduleUpgradeTask {
<# Wait for running chef-client to finish up to n times. If it has not finished after maxcount tries, then reschedule the upgrade task inMinutes minutes in the future and exit.
<# Wait for running Chef Infra Client to finish up to n times. If it has not finished after maxcount tries, then reschedule the upgrade task inMinutes minutes in the future and exit.
#>
param(
[Parameter(Mandatory=$false)]
Expand All @@ -357,11 +357,11 @@ def wait_for_chef_client_or_reschedule_upgrade_task_function
while ($status -gt 0) {
$count++
if ($count -gt $maxcount) {
Write-Output "Chef cannot be upgraded while in use. Rescheduling the upgrade in $inMinutes minutes..."
Write-Output "Chef Infra Client cannot be upgraded while in use. Rescheduling the upgrade in $inMinutes minutes..."
RescheduleTask Chef_upgrade $inMinutes
exit 0
}
Write-Output "Chef cannot be upgraded while in use - Attempt $count of $maxcount. Sleeping for 60 seconds and retrying..."
Write-Output "Chef Infra Client cannot be upgraded while in use - Attempt $count of $maxcount. Sleeping for 60 seconds and retrying..."
Start-Sleep 60
$status = (Get-WmiObject Win32_Process -Filter "name = 'ruby.exe'" | Select-Object CommandLine | select-string 'opscode').count
}
Expand Down Expand Up @@ -499,7 +499,7 @@ def execute_install_script(install_script)

license_provided = node['chef_client']['chef_license'] || ''

powershell_script 'name' do
powershell_script 'Chef Infra Client Upgrade Script' do
code <<-EOH
$command = {
$timestamp = Get-Date
Expand Down Expand Up @@ -601,7 +601,7 @@ def execute_install_script(install_script)
upgrade_command = Mixlib::ShellOut.new(install_script, timeout: new_resource.install_timeout)
upgrade_command.run_command
if upgrade_command.exitstatus != 0
raise "Error updating chef-client. exit code: #{upgrade_command.exitstatus}.\nSTDERR: #{upgrade_command.stderr}\nSTDOUT: #{upgrade_command.stdout}"
raise "Error updating Chef Infra Client. exit code: #{upgrade_command.exitstatus}.\nSTDERR: #{upgrade_command.stderr}\nSTDOUT: #{upgrade_command.stdout}"
end
end
end
Expand Down Expand Up @@ -629,7 +629,7 @@ def execute_install_script(install_script)
# sysvinit won't restart after we exit, potentially use cron to do so
# either trust the chef-client cookbook's init scripts or the users choice
if (node['chef_client'] && node['chef_client']['init_style'] == 'init') || node['chef_client_updater']['restart_chef_via_cron']
Chef::Log.warn 'Chef Client was upgraded, scheduling chef-client start via cron in 5 minutes'
Chef::Log.warn 'Chef Infra Client was upgraded, scheduling Chef Infra Client start via cron in 5 minutes'
cron_time = Time.now + 300
start_cmd = if platform_family?('aix')
'/usr/bin/startsrc -s chef > /dev/console 2>&1'
Expand All @@ -652,7 +652,7 @@ def execute_install_script(install_script)
raise
rescue Exception => e # rubocop:disable Lint/RescueException
if ::File.exist?(chef_backup_dir)
Chef::Log.warn "CHEF UPGRADE ABORTED due to #{e}: rolling back to #{chef_backup_dir} copy"
Chef::Log.warn "CHEF INFRA CLIENT UPGRADE ABORTED due to #{e}: rolling back to #{chef_backup_dir} copy"
move_opt_chef(chef_backup_dir, chef_install_dir) unless platform_family?('windows')
else
Chef::Log.warn "NO #{chef_backup_dir} DIR TO ROLL BACK TO!"
Expand Down
2 changes: 1 addition & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Cookbook:: chef_client_updater
# Recipe:: default
#
# Copyright:: 2016-2018, Chef Software, Inc.
# Copyright:: 2016-2020, 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.
Expand Down
4 changes: 2 additions & 2 deletions resources/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Resource:: updater
#
# Copyright:: 2016-2018, Will Jordan
# Copyright:: 2016-2018, Chef Software Inc.
# Copyright:: 2016-2020, 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.
Expand All @@ -20,7 +20,7 @@

# NOTE: this cookbook uses Chef-11 backwards compatible syntax to support
# upgrades from Chef 11.x and this pattern should not be copied for any modern
# cookbook. This is a poor example cookbook of how to write Chef.
# cookbook. This is a poor example cookbook of how to write Chef.

provides :chef_client_updater

Expand Down
2 changes: 1 addition & 1 deletion test/cookbooks/test/recipes/license.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
node.override['chef_client']['chef_license'] = 'accept'

chef_client_updater 'Install Chef 15' do
chef_client_updater 'Install Chef Infra Client 15' do
channel 'stable'
version '15'
post_install_action 'exec'
Expand Down

0 comments on commit 03ac509

Please sign in to comment.