chef-boneyard / chef-client

Development repository for Chef Client cookbook
http://supermarket.chef.io/cookbooks/chef-client
Apache License 2.0
175 stars 421 forks source link

no chef-client command in cron entry #714

Closed corbesero closed 4 years ago

corbesero commented 4 years ago

chef-client version: 13.8.5 chef-client cookbook version: 12.3.1

The cookbook is generating the following cron entry, which is misisng the chef-client in the command line.

This seems tro be a recent development.

# Generated by Chef. Changes will be overwritten.
LC_ALL=en_US.UTF-8

15,45 */1 * * * root /bin/sleep 88; /bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin --no-fork --no-color --once -c /etc/chef/client.rb > /var/log/chef/var/log/chef-client.last 2>&1

Here are the environment attributes

    "chef_client": {
      "config": {
        "verify_api_cert": false
      },
      "cron": {
        "environment_variables": {
          "LC_ALL": "en_US.UTF-8"
        },
        "hour": "*/1",
        "log_file": "/var/log/chef-client.last",
        "minute": "15,45"
      },
      "handler": {}
    },
phiggins commented 4 years ago

That command is generated here: https://github.com/chef-cookbooks/chef-client/blob/0d28b03e3c83af8a7342faec851683193a025c53/resources/cron.rb#L88-L99

To get the output you provided, new_resource.chef_binary_path would have to be getting overwritten somewhere. Is that or node['chef_client']['bin'] being set anywhere? https://github.com/chef-cookbooks/chef-client/blob/7ae6c2ba4da57412029ec5cd2dde46f9be4d42df/recipes/task.rb#L41

corbesero commented 4 years ago

I saw that in the docs, and I tried explicitly setting it to that value. That didn't help. And, I just checked all my node attributes. It is set to the default. I constrained the chef-client cookbook back to 11.5.0, and that works. (A correct cron entry is generated.) I can live with that in the short term, but I really would like to know what is broken.

corbesero commented 4 years ago

I have done a few more experiments. I am seeing this behavior in all the 12.x versions of the chef-client-cookbook. I also tried newer chef-client executables (13.12 and 14.15), but the cron is still not correct.

cbolgrihn commented 4 years ago

I have a similar issue, the /etc/cron.d/chef-client file that the code is creating looks to be either appending /dev/null 2>&1 or is not replacing it correctly. This is causing the cron job not to run since /var/log/chef/dev/null doesn't exist , here is what my line looks like: 0,30 root /bin/sleep 203; /opt/chef/bin/chef-client -c /etc/chef/client.rb > /var/log/chef/dev/null 2>&1

if this helps too: chef_version=14.7.17 platform=redhat platform_version=7.7

gaelik commented 4 years ago

Glad it ain’t just me, same issue with chef 15 and /dev/null being appended at the end of the redirect file..opened zendesk ticket #26188

tas50 commented 4 years ago

This should be fixed with 12.3.2. Please let me know if you're still seeing issues folks.

-Tim

cbolgrihn commented 4 years ago

I finally got time to circle back to this and see that the 12.3.2 code is still appending /dev/null to the log_file /var/log/chef in my /etc/cron.d/chef-client cron entry. I'm wondering if the attribute in the /attributes/default.rb in the following section should have client.log in the log_file instead of /dev/null

Configuration for chef-client::cron recipe.

default['chef_client']['cron'] = { 'minute' => '0,30', 'hour' => '', 'weekday' => '', 'path' => nil, 'environment_variables' => nil, #'log_file' => '/dev/null', 'log_file' => 'client.log', 'append_log' => false, 'use_cron_d' => false, 'mailto' => nil, 'nice_path' => '/bin/nice', }

If /dev/null is really where the log_file should be pointing to then should it be left as the attribute in the above file and the log_file be removed from the cmd line as seen below commented out in the /recipes/cron.rb file:

cron 'chef-client' do minute node['chef_client']['cron']['minute'] hour node['chef_client']['cron']['hour'] weekday node['chef_client']['cron']['weekday'] path node['chef_client']['cron']['path'] if node['chef_client']['cron']['path'] mailto node['chef_client']['cron']['mailto'] if node['chef_client']['cron']['mailto'] user 'root' cmd = '' cmd << "/bin/sleep #{sleep_time}; " if sleep_time cmd << "#{env_vars} " if env_vars? cmd << "#{node['chef_client']['cron']['nice_path']} -n #{process_priority} " if process_priority **cmd << "#{node['chef_client']['bin']} #{daemon_options}#{append_log} #{log_file} 2>&1"

cmd << "#{node['chef_client']['bin']} #{daemon_options}#{append_log} #{ } 2>&1"**

cmd << ' || echo "Chef client execution failed"' if node['chef_client']['cron']['mailto']
command cmd

end