From 541ddf990024bb235eb44265f584125dd641063f Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 7 Aug 2019 21:16:42 +0100 Subject: [PATCH] Configure cron to run in the local timezone of each machine --- cookbooks/tools/recipes/default.rb | 23 +++++++++++++++++++ .../tools/templates/default/cron.service.erb | 2 ++ 2 files changed, 25 insertions(+) create mode 100644 cookbooks/tools/templates/default/cron.service.erb diff --git a/cookbooks/tools/recipes/default.rb b/cookbooks/tools/recipes/default.rb index d228d2a4f..5154ecd12 100644 --- a/cookbooks/tools/recipes/default.rb +++ b/cookbooks/tools/recipes/default.rb @@ -35,6 +35,7 @@ package %w[ iotop lvm2 rsyslog + cron ] service "rsyslog" do @@ -51,3 +52,25 @@ end file "/etc/init.d/screen-cleanup" do action :delete end + +# Create drop in directory for cron service +directory "/etc/systemd/system/cron.service.d" do + owner "root" + group "root" + mode 0o755 +end + +# Configure cron to run in the local timezone of the machine +template "/etc/systemd/system/cron.service.d/chef.conf" do + source "cron.service.erb" + owner "root" + group "root" + mode 0o644 + notifies :restart, "service[cron]" + only_if { node[:timezone] } +end + +# Make sure cron is running +service "cron" do + action [:enable, :start] +end diff --git a/cookbooks/tools/templates/default/cron.service.erb b/cookbooks/tools/templates/default/cron.service.erb new file mode 100644 index 000000000..c659ab22e --- /dev/null +++ b/cookbooks/tools/templates/default/cron.service.erb @@ -0,0 +1,2 @@ +[Service] +Environment=TZ=<%= node[:timezone] -%> -- 2.43.2