Skip to content

Commit

Permalink
Attempt at creating a dist flag for this cookbook
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Cable <[email protected]>
  • Loading branch information
patcable committed Jul 6, 2020
1 parent edc69c8 commit 1d3d60b
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 83 deletions.
61 changes: 32 additions & 29 deletions attributes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@
'verify_api_cert' => true,
}

# If you're using a community maintained fork of Chef, then set this to the appropriate name.
default['chef_client']['dist'] = 'chef'

# Accept the chef license when running the chef service
default['chef_client']['chef_license'] = nil

default['chef_client']['log_file'] = 'client.log'
default['chef_client']['interval'] = '1800'
default['chef_client']['splay'] = '300'
default['chef_client']['conf_dir'] = '/etc/chef'
default['chef_client']['bin'] = '/opt/chef/bin/chef-client'
default['chef_client']['conf_dir'] = "/etc/#{node['chef_client']['dist']}"
default['chef_client']['bin'] = "/opt/#{node['chef_client']['dist']}/bin/#{node['chef_client']['dist']}-client"

# Set a sane default log directory location, overriden by specific
# platforms below.
default['chef_client']['log_dir'] = '/var/log/chef'
default['chef_client']['log_dir'] = "/var/log/#{node['chef_client']['dist']}"

# If log file is used, default permissions so everyone can read
default['chef_client']['log_perm'] = '640'
Expand Down Expand Up @@ -77,7 +80,7 @@
default['chef_client']['task']['password'] = nil # Password is only required for non-system users
default['chef_client']['task']['start_time'] = nil
default['chef_client']['task']['start_date'] = nil
default['chef_client']['task']['name'] = 'chef-client'
default['chef_client']['task']['name'] = "#{node['chef_client']['dist']}-client"

default['chef_client']['load_gems'] = {}

Expand Down Expand Up @@ -113,31 +116,31 @@
case node['platform_family']
when 'aix'
default['chef_client']['init_style'] = 'src'
default['chef_client']['svc_name'] = 'chef'
default['chef_client']['run_path'] = '/var/run/chef'
default['chef_client']['file_cache_path'] = '/var/spool/chef'
default['chef_client']['file_backup_path'] = '/var/lib/chef'
default['chef_client']['log_dir'] = '/var/adm/chef'
default['chef_client']['svc_name'] = node['chef_client']['dist']
default['chef_client']['run_path'] = "/var/run/#{node['chef_client']['dist']}"
default['chef_client']['file_cache_path'] = "/var/spool/#{node['chef_client']['dist']}"
default['chef_client']['file_backup_path'] = "/var/lib/#{node['chef_client']['dist']}"
default['chef_client']['log_dir'] = "/var/adm/#{node['chef_client']['dist']}"
when 'amazon', 'rhel', 'fedora', 'debian', 'suse', 'clearlinux'
default['chef_client']['init_style'] = node['init_package']
default['chef_client']['run_path'] = '/var/run/chef'
default['chef_client']['file_cache_path'] = '/var/cache/chef'
default['chef_client']['file_backup_path'] = '/var/lib/chef'
default['chef_client']['run_path'] = "/var/run/#{node['chef_client']['dist']}"
default['chef_client']['file_cache_path'] = "/var/cache/#{node['chef_client']['dist']}"
default['chef_client']['file_backup_path'] = "/var/lib/#{node['chef_client']['dist']}"
default['chef_client']['chkconfig']['start_order'] = 98
default['chef_client']['chkconfig']['stop_order'] = 02
when 'freebsd'
default['chef_client']['init_style'] = 'bsd'
default['chef_client']['run_path'] = '/var/run'
default['chef_client']['file_cache_path'] = '/var/chef/cache'
default['chef_client']['file_backup_path'] = '/var/chef/backup'
default['chef_client']['file_cache_path'] = "/var/#{node['chef_client']['dist']}/cache"
default['chef_client']['file_backup_path'] = "/var/#{node['chef_client']['dist']}/backup"
# don't use bsd paths per COOK-1379
when 'mac_os_x'
default['chef_client']['init_style'] = 'launchd'
default['chef_client']['log_dir'] = '/Library/Logs/Chef'
default['chef_client']['log_dir'] = "/Library/Logs/#{node['chef_client']['dist'].capitalize}"
# Launchd doesn't use pid files
default['chef_client']['run_path'] = '/var/run/chef'
default['chef_client']['file_cache_path'] = '/Library/Caches/Chef'
default['chef_client']['file_backup_path'] = '/Library/Caches/Chef/Backup'
default['chef_client']['run_path'] = "/var/run/#{node['chef_client']['dist']}"
default['chef_client']['file_cache_path'] = "/Library/Caches/#{node['chef_client']['dist'].capitalize}"
default['chef_client']['file_backup_path'] = "/Library/Caches/#{node['chef_client']['dist'].capitalize}/Backup"
# Set to 'daemon' if you want chef-client to run
# continuously with the -d and -s options, or leave
# as 'interval' if you want chef-client to be run
Expand All @@ -147,25 +150,25 @@
default['chef_client']['launchd_self-update'] = false
when 'openindiana', 'opensolaris', 'nexentacore', 'solaris2', 'omnios'
default['chef_client']['init_style'] = 'smf'
default['chef_client']['run_path'] = '/var/run/chef'
default['chef_client']['file_cache_path'] = '/var/chef/cache'
default['chef_client']['file_backup_path'] = '/var/chef/backup'
default['chef_client']['run_path'] = "/var/run/#{node['chef_client']['dist']}"
default['chef_client']['file_cache_path'] = "/var/#{node['chef_client']['dist']}/cache"
default['chef_client']['file_backup_path'] = "/var/#{node['chef_client']['dist']}/backup"
default['chef_client']['method_dir'] = '/lib/svc/method'
default['chef_client']['bin_dir'] = '/usr/bin'
default['chef_client']['locale'] = 'en_US.UTF-8'
default['chef_client']['env_path'] = '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
when 'smartos'
default['chef_client']['init_style'] = 'smf'
default['chef_client']['run_path'] = '/var/run/chef'
default['chef_client']['file_cache_path'] = '/var/chef/cache'
default['chef_client']['file_backup_path'] = '/var/chef/backup'
default['chef_client']['run_path'] = "/var/run/#{node['chef_client']['dist']}"
default['chef_client']['file_cache_path'] = "/var/#{node['chef_client']['dist']}/cache"
default['chef_client']['file_backup_path'] = "/var/#{node['chef_client']['dist']}/backup"
default['chef_client']['method_dir'] = '/opt/local/lib/svc/method'
default['chef_client']['bin_dir'] = '/opt/local/bin'
default['chef_client']['locale'] = 'en_US.UTF-8'
default['chef_client']['env_path'] = '/usr/local/sbin:/usr/local/bin:/opt/local/sbin:/opt/local/bin:/usr/sbin:/usr/bin:/sbin'
when 'windows'
default['chef_client']['init_style'] = 'windows'
default['chef_client']['conf_dir'] = 'C:/chef'
default['chef_client']['conf_dir'] = "C:/#{node['chef_client']['dist']}"
default['chef_client']['run_path'] = "#{node['chef_client']['conf_dir']}/run"
default['chef_client']['file_cache_path'] = "#{node['chef_client']['conf_dir']}/cache"
default['chef_client']['file_backup_path'] = "#{node['chef_client']['conf_dir']}/backup"
Expand All @@ -174,8 +177,8 @@
else
default['chef_client']['init_style'] = 'none'
default['chef_client']['run_path'] = '/var/run'
default['chef_client']['file_cache_path'] = '/var/chef/cache'
default['chef_client']['file_backup_path'] = '/var/chef/backup'
default['chef_client']['file_cache_path'] = "/var/#{node['chef_client']['dist']}/cache"
default['chef_client']['file_backup_path'] = "/var/#{node['chef_client']['dist']}/backup"
end

# Need to set this Option in client.rb
Expand All @@ -186,7 +189,7 @@
default['chef_client']['log_rotation']['prerotate'] = nil
default['chef_client']['log_rotation']['postrotate'] = case node['chef_client']['init_style']
when 'systemd'
node['chef_client']['systemd']['timer'] ? '' : 'systemctl reload chef-client.service >/dev/null || :'
node['chef_client']['systemd']['timer'] ? '' : "systemctl reload #{node['chef_client']['dist']}-client.service >/dev/null || :"
else
'/etc/init.d/chef-client reload >/dev/null || :'
"/etc/init.d/#{node['chef_client']['dist']}-client reload >/dev/null || :"
end
14 changes: 7 additions & 7 deletions recipes/bsd_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ::Chef::Recipe

# libraries/helpers.rb method to DRY directory creation resources
client_bin = find_chef_client
Chef::Log.debug("Using chef-client binary at #{client_bin}")
Chef::Log.debug("Using #{node['chef_client']['dist']}-client binary at #{client_bin}")
node.default['chef_client']['bin'] = client_bin
create_chef_directories

Expand All @@ -20,7 +20,7 @@ class ::Chef::Recipe
action :create
end

template '/usr/local/etc/rc.d/chef-client' do
template "/usr/local/etc/rc.d/#{node['chef_client']['dist']}-client" do
source 'default/freebsd/chef-client.erb'
owner 'root'
group 'wheel'
Expand All @@ -29,21 +29,21 @@ class ::Chef::Recipe
end

# Remove wrong rc.d script created by an older version of cookbook
file '/etc/rc.d/chef-client' do
file "/etc/rc.d/#{node['chef_client']['dist']}-client" do
action :delete
end

template '/etc/rc.conf.d/chef' do
template "/etc/rc.conf.d/#{node['chef_client']['dist']}" do
source 'default/freebsd/chef.erb'
mode '0644'
notifies :start, 'service[chef-client]', :delayed
notifies :start, "service[#{node['chef_client']['dist']}-client]", :delayed
end

service 'chef-client' do
service "#{node['chef_client']['dist']}-client" do
supports status: true, restart: true
action [:start]
end

else
log "You specified service style 'bsd'. You will need to set up your rc.local file. Hint: chef-client -i #{node['chef_client']['client_interval']} -s #{node['chef_client']['client_splay']}"
log "You specified service style 'bsd'. You will need to set up your rc.local file. Hint: #{node['chef_client']['dist']}-client -i #{node['chef_client']['client_interval']} -s #{node['chef_client']['client_splay']}"
end
2 changes: 1 addition & 1 deletion recipes/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ::Chef::Recipe
node.default['chef_client']['config']['log_location'] = log_path

if node['os'] == 'linux'
logrotate_app 'chef-client' do
logrotate_app "#{node['chef_client']['dist']}-client" do
path [log_path]
rotate node['chef_client']['logrotate']['rotate']
frequency node['chef_client']['logrotate']['frequency']
Expand Down
23 changes: 12 additions & 11 deletions recipes/cron.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,39 @@ class ::Chef::Recipe

# Stop any running chef-client services
if node['os'] == 'linux'
service 'chef-client' do
service "#{node['chef_client']['dist']}-client" do
supports status: true, restart: true
action [:disable, :stop]
ignore_failure true
end

file '/etc/init.d/chef-client' do
file "/etc/init.d/#{node['chef_client']['dist']}-client" do
action :delete
end
end

case node['platform_family']
when 'openindiana', 'opensolaris', 'nexentacore', 'solaris2', 'smartos', 'omnios'
service 'chef-client' do
service "#{node['chef_client']['dist']}-client" do
supports status: true, restart: true
action [:disable, :stop]
ignore_failure true
end

when 'freebsd'
template '/etc/rc.d/chef-client' do
template "/etc/rc.d/#{node['chef_client']['dist']}-client" do
source 'default/freebsd/chef-client.erb'
owner 'root'
group 'wheel'
variables client_bin: client_bin
mode '0755'
end

file '/etc/rc.conf.d/chef' do
file "/etc/rc.conf.d/#{node['chef_client']['dist']}" do
action :delete
end

service 'chef-client' do
service "#{node['chef_client']['dist']}-client" do
supports status: true, restart: true
action [:stop]
end
Expand All @@ -73,11 +73,12 @@ class ::Chef::Recipe
# If "use_cron_d" is set to true, delete the cron entry that uses the cron
# resource built in to Chef and instead use the cron_d LWRP.
if node['chef_client']['cron']['use_cron_d']
cron 'chef-client' do
cron "#{node['chef_client']['dist']}-client" do
action :delete
end

chef_client_cron 'chef-client cron.d job' do
chef_client_cron "#{node['chef_client']['dist']}-client cron.d job" do
job_name "#{node['chef_client']['dist']}-client"
minute node['chef_client']['cron']['minute']
hour node['chef_client']['cron']['hour']
weekday node['chef_client']['cron']['weekday']
Expand All @@ -92,7 +93,7 @@ class ::Chef::Recipe
# Non-linux platforms don't support cron.d so we won't try to remove a cron_d resource.
# https://github.com/chef-cookbooks/cron/blob/master/resources/d.rb#L55
if node['os'] == 'linux'
cron_d 'chef-client' do
cron_d "#{node['chef_client']['dist']}-client" do
action :delete
end
end
Expand All @@ -102,7 +103,7 @@ class ::Chef::Recipe
append_log = node['chef_client']['cron']['append_log'] ? '>>' : '>'
daemon_options = " #{node['chef_client']['daemon_options'].join(' ')} " if node['chef_client']['daemon_options'].any?

cron 'chef-client' do
cron "#{node['chef_client']['dist']}-client" do
minute node['chef_client']['cron']['minute']
hour node['chef_client']['cron']['hour']
weekday node['chef_client']['cron']['weekday']
Expand All @@ -114,7 +115,7 @@ class ::Chef::Recipe
cmd << "#{env_vars} " if env_vars?
cmd << "#{node['chef_client']['cron']['nice_path']} -n #{process_priority} " if process_priority
cmd << "#{client_bin} #{daemon_options}#{append_log} #{log_file} 2>&1"
cmd << ' || echo "Chef client execution failed"' if node['chef_client']['cron']['mailto']
cmd << " || echo \"#{node['chef_client']['dist']} client execution failed\"" if node['chef_client']['cron']['mailto']
command cmd
end
end
8 changes: 4 additions & 4 deletions recipes/init_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ::Chef::Recipe
node.default['chef_client']['bin'] = client_bin
create_chef_directories

template '/etc/init.d/chef-client' do
template "/etc/init.d/#{node['chef_client']['dist']}-client" do
source 'redhat/init.d/chef-client.erb'
mode '0755'
variables(client_bin: client_bin,
Expand All @@ -20,13 +20,13 @@ class ::Chef::Recipe
notifies :restart, 'service[chef-client]', :delayed
end

template '/etc/sysconfig/chef-client' do
template "/etc/sysconfig/#{node['chef_client']['dist']}-client" do
source 'redhat/sysconfig/chef-client.erb'
mode '0644'
notifies :restart, 'service[chef-client]', :delayed
notifies :restart, "service[#{node['chef_client']['dist']}-client]", :delayed
end

service 'chef-client' do
service "#{node['chef_client']['dist']}-client" do
supports status: true, restart: true
action [:enable, :start]
end
14 changes: 7 additions & 7 deletions recipes/launchd_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class ::Chef::Recipe

# libraries/helpers.rb method to DRY directory creation resources
client_bin = find_chef_client
Chef::Log.debug("Using chef-client binary at #{client_bin}")
Chef::Log.debug("Using #{node['chef_client']['dist']}-client binary at #{client_bin}")
node.default['chef_client']['bin'] = client_bin

create_chef_directories

template '/Library/LaunchDaemons/com.chef.chef-client.plist' do
template "/Library/LaunchDaemons/com.#{node['chef_client']['dist']}.#{node['chef_client']['dist']}-client.plist" do
source 'com.chef.chef-client.plist.erb'
mode '0644'
variables(
Expand All @@ -25,15 +25,15 @@ class ::Chef::Recipe
splay: node['chef_client']['splay'],
working_dir: node['chef_client']['launchd_working_dir']
)
notifies :restart, 'macosx_service[com.chef.chef-client]' if node['chef_client']['launchd_self-update']
notifies :restart, "macosx_service[com.#{node['chef_client']['dist']}.#{node['chef_client']['dist']}-client]" if node['chef_client']['launchd_self-update']
end

macosx_service 'com.chef.chef-client' do
macosx_service "com.#{node['chef_client']['dist']}.#{node['chef_client']['dist']}-client" do
action :nothing
end

macosx_service 'chef-client' do
service_name 'com.chef.chef-client'
plist '/Library/LaunchDaemons/com.chef.chef-client.plist'
macosx_service "#{node['chef_client']['dist']}-client" do
service_name "com.#{node['chef_client']['dist']}.#{node['chef_client']['dist']}-client"
plist "/Library/LaunchDaemons/com.#{node['chef_client']['dist']}.#{node['chef_client']['dist']}-client.plist"
action :start
end
16 changes: 8 additions & 8 deletions recipes/smf_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ::Chef::Recipe

# libraries/helpers.rb method to DRY directory creation resources
client_bin = find_chef_client
Chef::Log.debug("Using chef-client binary at #{client_bin}")
Chef::Log.debug("Using #{node['chef_client']['dist']}-client binary at #{client_bin}")
node.default['chef_client']['bin'] = client_bin
create_chef_directories

Expand All @@ -18,15 +18,15 @@ class ::Chef::Recipe
end

local_path = ::File.join(Chef::Config[:file_cache_path], '/')
template "#{node['chef_client']['method_dir']}/chef-client" do
template "#{node['chef_client']['method_dir']}/#{node['chef_client']['dist']}-client" do
source 'solaris/chef-client.erb'
owner 'root'
group 'root'
mode '0555'
notifies :restart, 'service[chef-client]'
notifies :restart, "service[#{node['chef_client']['dist']}-client]"
end

template(local_path + 'chef-client.xml') do
template(local_path + node['chef_client']['dist'] + '-client.xml') do
if node['platform_version'].to_f >= 5.11 && !platform?('smartos')
source 'solaris/manifest-5.11.xml.erb'
else
Expand All @@ -37,14 +37,14 @@ class ::Chef::Recipe
mode '0644'
end

execute 'load chef-client manifest' do
execute "load #{node['chef_client']['dist']}-client manifest" do
action :nothing
command "/usr/sbin/svccfg import #{local_path}chef-client.xml"
notifies :restart, 'service[chef-client]'
notifies :restart, "service[#{node['chef_client']['dist']}-client]"
end

service 'chef-client' do
service "#{node['chef_client']['dist']}-client" do
action [:enable, :start]
provider Chef::Provider::Service::Solaris
notifies :run, 'execute[load chef-client manifest]', :before
notifies :run, "execute[load #{node['chef_client']['dist']}-client manifest]", :before
end
2 changes: 1 addition & 1 deletion recipes/src_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ::Chef::Recipe

# libraries/helpers.rb method to DRY directory creation resources
client_bin = find_chef_client
Chef::Log.debug("Using chef-client binary at #{client_bin}")
Chef::Log.debug("Using #{node['chef_client']['dist']}-client binary at #{client_bin}")
node.default['chef_client']['bin'] = client_bin
create_chef_directories

Expand Down
Loading

0 comments on commit 1d3d60b

Please sign in to comment.