class Chef::Resource::ChefClientCron

Public Instance Methods

client_command() click to toggle source

The complete cron command to run

@return [String]

# File lib/chef/resource/chef_client_cron.rb, line 196
def client_command
  cmd = ""
  cmd << "/bin/sleep #{splay_sleep_time(new_resource.splay)}; "
  cmd << "#{which("nice")} -n #{new_resource.nice} " if new_resource.nice
  cmd << "#{new_resource.chef_binary_path} "
  cmd << "#{new_resource.daemon_options.join(" ")} " unless new_resource.daemon_options.empty?
  cmd << "-c #{::File.join(new_resource.config_directory, "client.rb")} "
  cmd << "--chef-license accept " if new_resource.accept_chef_license
  cmd << log_command
  cmd << " || echo \"#{ChefUtils::Dist::Infra::PRODUCT} execution failed\"" if new_resource.mailto
  cmd
end
cron_resource_type() click to toggle source

The type of cron resource to run. Linux systems all support the /etc/cron.d directory and can use the cron_d resource, but Solaris / AIX / FreeBSD need to use the crontab via the legacy cron resource.

@return [Symbol]

# File lib/chef/resource/chef_client_cron.rb, line 229
def cron_resource_type
  linux? ? :cron_d : :cron
end
log_command() click to toggle source

The portion of the overall cron job that handles logging based on the append_log_file property

@return [String]

# File lib/chef/resource/chef_client_cron.rb, line 214
def log_command
  if new_resource.append_log_file
    ">> #{::File.join(new_resource.log_directory, new_resource.log_file_name)} 2>&1"
  else
    "> #{::File.join(new_resource.log_directory, new_resource.log_file_name)} 2>&1"
  end
end
splay_sleep_time(splay) click to toggle source

Generate a uniformly distributed unique number to sleep from 0 to the splay time

@param [Integer] splay The number of seconds to splay

@return [Integer]

# File lib/chef/resource/chef_client_cron.rb, line 185
def splay_sleep_time(splay)
  seed = node["shard_seed"] || Digest::MD5.hexdigest(node.name).to_s.hex
  random = Random.new(seed.to_i)
  random.rand(splay)
end