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

log file in /etc/cron.d/chef-client evaluates to /var/log/chef/dev/null #722

Closed haidangwa closed 3 years ago

haidangwa commented 3 years ago

Due to https://github.com/chef-cookbooks/chef-client/blob/75a99f10b19302db2bde16bf624f82f4d6b4ca26/attributes/default.rb#L56 default value and when node['chef-client']['cron']['use_cron_d'] == true, the cron command writes to a log file at /var/log/chef/dev/null instead of /dev/null.

# cat /etc/cron.d/chef-client 
# Generated by Chef. Changes will be overwritten.

0,30 * * * * root /bin/sleep 66; /opt/chef/bin/chef-client -c /etc/chef/client.rb > /var/log/chef/dev/null 2>&1
[root@ip-10-26-136-236 ~]# Connection to 10.26.136.236 closed by remote host.
bcg62 commented 3 years ago

also seeing this

garrettben commented 3 years ago

Seeing this after updating the chef-client cookbook today as well.

Put the following override in my base role as a workaround:

{
  "chef_client": {
    "cron": {
      "log_file": "chef-client.log"
    }
  }
}

It should just overwrite chef-client.log on every run.

haidangwa commented 3 years ago

Since this cron command contains -c /etc/chef/client.rb and the log_location that is generated (by default) in client.rb is already set to /var/log/chef/client.log, I would say that the attempted redirect to a log file or /dev/null is not needed at all.

jasonwbarnett commented 3 years ago

I am also experiencing this issue on RHEL 7.

I looked at the cookbook and the attribute names and/or their use is inconsistent. There is a log_dir and a log_file. That Indicates to me that one (i.e. log_file) is a filename (without the directory or absolute path) and the other (i.e. log_dir) is the absolute path where the log file lives. The problem is that the log_file attribute is set to /dev/null which is an absolute path and violates the previous stated assumptions.

jasonwbarnett commented 3 years ago

@tas50 I'm pretty sure this was resolved by https://github.com/chef-cookbooks/chef-client/pull/727

tas50 commented 3 years ago

Should be now

SeanSith commented 3 years ago

This didn't fix the issue above. Running 12.3.4 still has it showing up in cron as:

*/30 * * * * root /bin/sleep 24; /usr/bin/cinc-client -c /etc/cinc/client.rb >> /var/log/cinc/dev/null 2>&1

my cookbook is specified as such:

node.default['chef_client']['init_style'] = 'none'
node.default['chef_client']['cron']['minute'] = '*/30'
node.default['chef_client']['cron']['hour'] = '*'
node.default['chef_client']['cron']['use_cron_d'] = true
node.default['chef_client']['cron']['append_log'] = true
node.default['chef_client']['cron']['environment_variables'] = {
  PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games'
}
node.override['chef_client']['bin'] = '/usr/bin/cinc-client'
node.override['chef_client']['conf_dir'] = '/etc/cinc'
node.override['chef_client']['log_dir'] = '/var/log/cinc'
node.override['chef_client']['log_file'] = 'client.log'
node.override['chef_client']['run_path'] = '/var/run/cinc'
node.override['chef_client']['file_backup_path'] = '/var/lib/cinc'
node.override['chef_client']['log_rotation']['postrotate'] = 'systemctl reload cinc-client.service >/dev/null || :'
ramereth commented 3 years ago

@SeanSith what version of Chef are you running? If you're using a newer version, then this would be a native resource in chef.