]> git.openstreetmap.org Git - chef.git/blob - cookbooks/ntp/recipes/default.rb
938aa47aca72f4b5bb52762c9e963df993d9abe2
[chef.git] / cookbooks / ntp / recipes / default.rb
1 #
2 # Cookbook Name:: ntp
3 # Recipe:: default
4 #
5 # Copyright 2010, OpenStreetMap Foundation.
6 # Copyright 2009, Opscode, Inc
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19
20 require "socket"
21
22 package "ntp"
23 package "ntpdate"
24 package "tzdata"
25
26 execute "dpkg-reconfigure-tzdata" do
27   action :nothing
28   command "/usr/sbin/dpkg-reconfigure -f noninteractive tzdata"
29   user "root"
30   group "root"
31 end
32
33 file "/etc/timezone" do
34   owner "root"
35   group "root"
36   mode 0644
37   content "#{node[:tz]}\n"
38   notifies :run, resources(:execute => "dpkg-reconfigure-tzdata"), :immediately
39 end
40
41 service "ntp" do
42   action [ :enable, :start ]
43   supports :status => true, :restart => true
44 end
45
46 template "/etc/ntp.conf" do
47   source "ntp.conf.erb"
48   owner "root"
49   group "root"
50   mode 0644
51   notifies :restart, resources(:service => "ntp")
52 end
53
54 munin_plugins = [ "ntp_kernel_err", "ntp_kernel_pll_freq", "ntp_kernel_pll_off", "ntp_offset" ]
55
56 munin_plugin "ntp_kernel_err"
57 munin_plugin "ntp_kernel_pll_freq"
58 munin_plugin "ntp_kernel_pll_off"
59 munin_plugin "ntp_offset"
60
61 if File.directory?("/etc/munin/plugins")
62   Dir.new("/etc/munin/plugins").each do |plugin|
63     if plugin.match(/^ntp_/) and not munin_plugins.include?(plugin)
64       munin_plugin plugin do
65         action :delete
66       end
67     end
68   end
69 end