Closed scalp42 closed 4 years ago
node['chef_client']['cron']['priority']
doesn't make it anymore to the cron.d file as well.
If someone comes across this, here's our workaround in a wrapper cookbook:
delete_resource(:chef_client_cron, 'chef-client cron.d job')
chef_client_cron_command = []
chef_client_cron_command << "/bin/sleep #{Random.rand(node['chef_client']['splay'].to_i)};"
chef_client_cron_command << node['chef_client']['cron']['environment_variables']
chef_client_cron_command << "#{node['chef_client']['cron']['nice_path']} -n #{node['chef_client']['cron']['priority']}" if node['chef_client']['cron']['priority']
chef_client_cron_command << node['chef_client']['bin']
chef_client_cron_command << node['chef_client']['daemon_options'] unless node['chef_client']['daemon_options'].empty?
chef_client_cron_command << "-c #{::File.join(node['chef_client']['conf_dir'], 'client.rb')}"
chef_client_cron_command << (node['chef_client']['cron']['append_log'] ? '>>' : '>')
chef_client_cron_command << "#{::File.join(node['chef_client']['log_dir'], node['chef_client']['cron']['log_file'])} 2>&1"
cron_d 'chef-client' do
minute node['chef_client']['cron']['minute']
hour node['chef_client']['cron']['hour']
weekday node['chef_client']['cron']['weekday']
month '*'
mailto node['chef_client']['cron']['mailto'] if node['chef_client']['cron']['mailto']
command chef_client_cron_command.flatten.join(' ').strip
end
I don't think this is fixed @ramereth or @tas50
As I mentioned we're not passing down the environment variables to the cron_command. We're passing additional arbitrary environment variables under which the cron job will be run but the behavior is different as node['chef_client']['cron']['environment_variables']
could be used as a hook to do whatever before the actual run.
This is about the environment variables that get passed before the cron command, see our work around:
chef_client_cron_command = []
chef_client_cron_command << "/bin/sleep #{splay};"
chef_client_cron_command << node['chef_client']['cron']['environment_variables']
chef_client_cron_command << "#{node['chef_client']['cron']['nice_path']} -n #{node['chef_client']['cron']['priority']}" if node['chef_client']['cron']['priority']
chef_client_cron_command << node['chef_client']['bin']
chef_client_cron_command << node['chef_client']['daemon_options'] unless node['chef_client']['daemon_options'].empty?
chef_client_cron_command << "-c #{::File.join(node['chef_client']['conf_dir'], 'client.rb')}"
chef_client_cron_command << (node['chef_client']['cron']['append_log'] ? '>>' : '>')
chef_client_cron_command << "#{::File.join(node['chef_client']['log_dir'], node['chef_client']['cron']['log_file'])} 2>&1"
cron_d 'chef-client' do
minute node['chef_client']['cron']['minute']
hour node['chef_client']['cron']['hour']
weekday node['chef_client']['cron']['weekday']
month '*'
mailto node['chef_client']['cron']['mailto'] if node['chef_client']['cron']['mailto']
command chef_client_cron_command.flatten.join(' ').strip
end
@scalp42 I believe you can work around that by putting that in the node['chef_client']['cron']['path']
attribute. We do something like the following in ours: /usr/bin/flock -n /tmp/chef-client.lock /opt/chef/bin/chef-client
Sure but my point is that the behavior is changed here 🤷♂️
Hi folks,
Just noticed upgrading to 12.0.1 that the cron.d file won't include
node['chef_client']['cron']['environment_variables']
anymore.We use InSpec so we could catch it easily:
Attributes (we didn't change them):
Recipe (nothing was changed either):
I tracked it down to
chef_client_cron
(https://github.com/chef-cookbooks/chef-client/blob/master/resources/cron.rb#L84-L94) not having any notion of environment variables (which should come after thesleep
). For non Linux platforms, it'll work here: https://github.com/chef-cookbooks/chef-client/blob/master/recipes/cron.rb#L114Workaround is to just drop our own
cron_d
resource using the cookbook attributes but it'd be neat if upstream could just include it:In https://github.com/chef-cookbooks/chef-client/blob/master/recipes/cron.rb#L80-L89:
In https://github.com/chef-cookbooks/chef-client/blob/master/resources/cron.rb#L84-L94
Cheers!
cc @tas50 for visibility