5 # Copyright:: 2012, OpenStreetMap Foundation
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
11 # https://www.apache.org/licenses/LICENSE-2.0
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
22 include_recipe "munin"
23 include_recipe "sysfs"
24 include_recipe "tools"
26 ohai_plugin "hardware" do
27 template "ohai.rb.erb"
30 case node[:cpu][:"0"][:vendor_id]
32 package "intel-microcode"
34 package "amd64-microcode"
37 if node[:dmi] && node[:dmi][:system]
38 case node[:dmi][:system][:manufacturer]
40 manufacturer = node[:dmi][:base_board][:manufacturer]
41 product = node[:dmi][:base_board][:product_name]
43 manufacturer = node[:dmi][:system][:manufacturer]
44 product = node[:dmi][:system][:product_name]
47 manufacturer = "Unknown"
53 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric")
61 package "hp-health" do
63 notifies :restart, "service[hp-health]"
66 service "hp-health" do
67 action [:enable, :start]
68 supports :status => true, :restart => true
71 if product.end_with?("Gen8", "Gen9")
74 notifies :restart, "service[hp-ams]"
78 action [:enable, :start]
79 supports :status => true, :restart => true
86 when "TYAN Computer Corporation"
93 package "open-vm-tools"
95 # Remove timeSync plugin completely
96 # https://github.com/vmware/open-vm-tools/issues/302
97 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
99 notifies :restart, "service[open-vm-tools]"
102 # Attempt to tell Host we are not interested in timeSync
103 execute "vmware-toolbox-cmd-timesync-disable" do
104 command "/usr/bin/vmware-toolbox-cmd timesync disable"
108 service "open-vm-tools" do
109 action [:enable, :start]
110 supports :status => true, :restart => true
114 units.sort.uniq.each do |unit|
115 service "serial-getty@ttyS#{unit}" do
116 action [:enable, :start]
120 # if we need a different / special kernel version to make the hardware
121 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
122 # ensure that we have the package installed. the grub template will
123 # make sure that this is the default on boot.
124 if node[:hardware][:grub][:kernel]
125 kernel_version = node[:hardware][:grub][:kernel]
127 package "linux-image-#{kernel_version}-generic"
128 package "linux-image-extra-#{kernel_version}-generic"
129 package "linux-headers-#{kernel_version}-generic"
130 package "linux-tools-#{kernel_version}-generic"
132 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
133 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
134 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
139 if File.exist?("/etc/default/grub")
140 execute "update-grub" do
142 command "/usr/sbin/update-grub"
145 template "/etc/default/grub" do
150 variables :units => units, :entry => grub_entry
151 notifies :run, "execute[update-grub]"
155 execute "update-initramfs" do
157 command "update-initramfs -u -k all"
162 template "/etc/initramfs-tools/conf.d/mdadm" do
163 source "initramfs-mdadm.erb"
167 notifies :run, "execute[update-initramfs]"
172 action [:enable, :start]
175 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
179 service "irqbalance" do
180 action [:start, :enable]
181 supports :status => false, :restart => true, :reload => false
184 # Link Layer Discovery Protocol Daemon
187 action [:start, :enable]
188 supports :status => true, :restart => true, :reload => true
194 if node[:virtualization][:role] != "guest" ||
195 (node[:virtualization][:system] != "lxc" &&
196 node[:virtualization][:system] != "lxd" &&
197 node[:virtualization][:system] != "openvz")
199 node[:kernel][:modules].each_key do |modname|
202 tools_packages << "ssacli"
203 status_packages["cciss-vol-status"] ||= []
205 tools_packages << "ssacli"
206 status_packages["cciss-vol-status"] ||= []
208 tools_packages << "lsiutil"
209 status_packages["mpt-status"] ||= []
210 when "mpt2sas", "mpt3sas"
211 tools_packages << "sas2ircu"
212 status_packages["sas2ircu-status"] ||= []
214 tools_packages << "megactl"
215 status_packages["megaraid-status"] ||= []
217 tools_packages << "megacli"
218 status_packages["megaclisas-status"] ||= []
220 tools_packages << "arcconf"
221 status_packages["aacraid-status"] ||= []
223 tools_packages << "areca"
227 node[:block_device].each do |name, attributes|
228 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
230 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
231 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
233 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
234 status_packages["cciss-vol-status"] |= [File.basename(sg)]
240 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
241 if tools_packages.include?(tools_package)
242 package tools_package
244 package tools_package do
250 if tools_packages.include?("areca")
255 repository "https://git.openstreetmap.org/private/areca.git"
259 not_if { ENV["TEST_KITCHEN"] }
262 directory "/opt/areca" do
268 if status_packages.include?("cciss-vol-status")
269 template "/usr/local/bin/cciss-vol-statusd" do
270 source "cciss-vol-statusd.erb"
274 notifies :restart, "service[cciss-vol-statusd]"
277 systemd_service "cciss-vol-statusd" do
278 description "Check cciss_vol_status values in the background"
279 exec_start "/usr/local/bin/cciss-vol-statusd"
281 protect_system "full"
283 no_new_privileges true
284 notifies :restart, "service[cciss-vol-statusd]"
287 systemd_service "cciss-vol-statusd" do
291 template "/usr/local/bin/cciss-vol-statusd" do
296 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
297 if status_packages.include?(status_package)
298 package status_package
300 template "/etc/default/#{status_package}d" do
301 source "raid.default.erb"
305 variables :devices => status_packages[status_package]
308 service "#{status_package}d" do
309 action [:start, :enable]
310 supports :status => false, :restart => true, :reload => false
311 subscribes :restart, "template[/etc/default/#{status_package}d]"
314 package status_package do
318 file "/etc/default/#{status_package}d" do
324 disks = if node[:hardware][:disk]
325 node[:hardware][:disk][:disks]
330 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
332 nvmes = if node[:hardware][:pci]
333 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
338 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
340 if !intel_ssds.empty? || !intel_nvmes.empty?
343 intel_ssd_tool_version = "3.0.25"
345 remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
346 source "https://downloadmirror.intel.com/29556/eng/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip"
349 execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
350 command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
351 cwd Chef::Config[:file_cache_path]
354 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux/isdct_#{intel_ssd_tool_version}-1_amd64.deb") }
357 dpkg_package "isdct" do
358 version "#{intel_ssd_tool_version}-1"
359 source "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
363 disks = disks.map do |disk|
364 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
366 if disk[:smart_device]
367 controller = node[:hardware][:disk][:controllers][disk[:controller]]
369 if controller && controller[:device]
370 device = controller[:device].sub("/dev/", "")
371 smart = disk[:smart_device]
373 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
374 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
375 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
376 elsif smart =~ /^.*,(\d+)$/
377 munin = "#{device}-#{Regexp.last_match(1)}"
378 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
379 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
382 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
383 device = Regexp.last_match(1)
386 device = disk[:device].sub("/dev/", "")
396 :hddtemp => munin.tr("-:", "_")
400 disks = disks.compact.uniq
402 if disks.count.positive?
403 package "smartmontools"
405 template "/etc/cron.daily/update-smart-drivedb" do
406 source "update-smart-drivedb.erb"
412 template "/usr/local/bin/smartd-mailer" do
413 source "smartd-mailer.erb"
419 template "/etc/smartd.conf" do
420 source "smartd.conf.erb"
424 variables :disks => disks
427 template "/etc/default/smartmontools" do
428 source "smartmontools.erb"
434 service "smartmontools" do
435 action [:enable, :start]
436 subscribes :reload, "template[/etc/smartd.conf]"
437 subscribes :restart, "template[/etc/default/smartmontools]"
440 # Don't try and do munin monitoring of disks behind
441 # an Areca controller as they only allow one thing to
442 # talk to the controller at a time and smartd will
443 # throw errors if it clashes with munin
444 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
447 munin_plugin "smart_#{disk[:munin]}" do
449 conf "munin.smart.erb"
450 conf_variables :disk => disk
455 action [:stop, :disable]
459 if disks.count.positive?
460 munin_plugin "hddtemp_smartctl" do
461 conf "munin.hddtemp.erb"
462 conf_variables :disks => disks
465 munin_plugin "hddtemp_smartctl" do
467 conf "munin.hddtemp.erb"
471 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
472 disks.map { |d| "smart_#{d[:munin]}" }
474 plugins.each do |plugin|
475 munin_plugin plugin do
477 conf "munin.smart.erb"
481 if File.exist?("/etc/mdadm/mdadm.conf")
482 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
483 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
488 file "/etc/mdadm/mdadm.conf" do
497 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
501 template "/etc/modules" do
510 subscribes :start, "template[/etc/modules]"
513 if node[:hardware][:watchdog]
516 template "/etc/default/watchdog" do
517 source "watchdog.erb"
521 variables :module => node[:hardware][:watchdog]
524 service "watchdog" do
525 action [:enable, :start]
529 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
532 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
533 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
534 chip = format("coretemp-isa-%04d", cpu)
536 temps = if File.exist?("#{coretemp}/name")
537 Dir.glob("#{coretemp}/temp*_input").map do |temp|
538 File.basename(temp).sub("temp", "").sub("_input", "").to_i
541 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
542 File.basename(temp).sub("temp", "").sub("_input", "").to_i
547 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
551 temps.each_with_index do |temp, index|
552 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
556 execute "/etc/sensors.d/chef.conf" do
558 command "/usr/bin/sensors -s"
563 template "/etc/sensors.d/chef.conf" do
564 source "sensors.conf.erb"
568 notifies :run, "execute[/etc/sensors.d/chef.conf]"
572 if node[:hardware][:shm_size]
573 execute "remount-dev-shm" do
575 command "/bin/mount -o remount /dev/shm"
584 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
585 notifies :run, "execute[remount-dev-shm]"