# include helper methods
class ::Chef::Recipe
  include ::Opscode::ChefClient::Helpers
end

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

dist_dir, conf_dir = value_for_platform_family(
  ['amazon'] => %w( redhat sysconfig ),
  ['debian'] => %w( debian default ),
  ['fedora'] => %w( redhat sysconfig ),
  ['rhel'] => %w( redhat sysconfig ),
  ['suse'] => %w( suse sysconfig )
)

template '/etc/init.d/chef-client' do
  source "#{dist_dir}/init.d/chef-client.erb"
  mode '755'
  variables client_bin: client_bin
  notifies :restart, 'service[chef-client]', :delayed
end

template "/etc/#{conf_dir}/chef-client" do
  source "#{dist_dir}/#{conf_dir}/chef-client.erb"
  mode '644'
  notifies :restart, 'service[chef-client]', :delayed
end

service 'chef-client' do
  supports status: true, restart: true
  action [:enable, :start]
end

# include helper methods
class ::Chef::Recipe
  include ::Opscode::ChefClient::Helpers
end

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

dist_dir, conf_dir = value_for_platform_family(
  %w(amazon rhel fedora) => %w( redhat sysconfig ),
  %w(debian) => %w( debian default ),
  %w(suse) => %w( suse sysconfig )
)

template '/etc/init.d/chef-client' do
  source "#{dist_dir}/init.d/chef-client.erb"
  mode '755'
  variables client_bin: client_bin
  notifies :restart, 'service[chef-client]', :delayed
end

template "/etc/#{conf_dir}/chef-client" do
  source "#{dist_dir}/#{conf_dir}/chef-client.erb"
  mode '644'
  notifies :restart, 'service[chef-client]', :delayed
end

service 'chef-client' do
  supports status: true, restart: true
  action [:enable, :start]
end

Simplify the platform logic in the init service recipe
Simplify the platform logic in the init service recipe

Signed-off-by: Tim Smith <764ef62106582a09ed09dfa0b6bff7c05fd7d1e4@chef.io>
