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 "prometheus"
24 include_recipe "sysfs"
25 include_recipe "tools"
27 ohai_plugin "hardware" do
28 template "ohai.rb.erb"
31 case node[:cpu][:"0"][:vendor_id]
33 package "intel-microcode"
35 package "amd64-microcode"
38 if node[:dmi] && node[:dmi][:system]
39 case node[:dmi][:system][:manufacturer]
41 manufacturer = node[:dmi][:base_board][:manufacturer]
42 product = node[:dmi][:base_board][:product_name]
44 manufacturer = node[:dmi][:system][:manufacturer]
45 product = node[:dmi][:system][:product_name]
48 manufacturer = "Unknown"
54 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric")
62 package "hp-health" do
64 notifies :restart, "service[hp-health]"
67 service "hp-health" do
68 action [:enable, :start]
69 supports :status => true, :restart => true
72 if product.end_with?("Gen8", "Gen9")
75 notifies :restart, "service[hp-ams]"
79 action [:enable, :start]
80 supports :status => true, :restart => true
87 when "TYAN Computer Corporation"
94 package "open-vm-tools"
96 # Remove timeSync plugin completely
97 # https://github.com/vmware/open-vm-tools/issues/302
98 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
100 notifies :restart, "service[open-vm-tools]"
103 # Attempt to tell Host we are not interested in timeSync
104 execute "vmware-toolbox-cmd-timesync-disable" do
105 command "/usr/bin/vmware-toolbox-cmd timesync disable"
109 service "open-vm-tools" do
110 action [:enable, :start]
111 supports :status => true, :restart => true
115 units.sort.uniq.each do |unit|
116 service "serial-getty@ttyS#{unit}" do
117 action [:enable, :start]
121 # if we need a different / special kernel version to make the hardware
122 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
123 # ensure that we have the package installed. the grub template will
124 # make sure that this is the default on boot.
125 if node[:hardware][:grub][:kernel]
126 kernel_version = node[:hardware][:grub][:kernel]
128 package "linux-image-#{kernel_version}-generic"
129 package "linux-image-extra-#{kernel_version}-generic"
130 package "linux-headers-#{kernel_version}-generic"
131 package "linux-tools-#{kernel_version}-generic"
133 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
134 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
135 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
140 if File.exist?("/etc/default/grub")
141 execute "update-grub" do
143 command "/usr/sbin/update-grub"
144 not_if { ENV["TEST_KITCHEN"] }
147 template "/etc/default/grub" do
152 variables :units => units, :entry => grub_entry
153 notifies :run, "execute[update-grub]"
157 execute "update-initramfs" do
159 command "update-initramfs -u -k all"
164 template "/etc/initramfs-tools/conf.d/mdadm" do
165 source "initramfs-mdadm.erb"
169 notifies :run, "execute[update-initramfs]"
174 action [:enable, :start]
177 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
181 service "irqbalance" do
182 action [:start, :enable]
183 supports :status => false, :restart => true, :reload => false
186 # Link Layer Discovery Protocol Daemon
189 action [:start, :enable]
190 supports :status => true, :restart => true, :reload => true
196 if node[:virtualization][:role] != "guest" ||
197 (node[:virtualization][:system] != "lxc" &&
198 node[:virtualization][:system] != "lxd" &&
199 node[:virtualization][:system] != "openvz")
201 node[:kernel][:modules].each_key do |modname|
204 tools_packages << "ssacli"
205 status_packages["cciss-vol-status"] ||= []
207 tools_packages << "ssacli"
208 status_packages["cciss-vol-status"] ||= []
210 tools_packages << "lsiutil"
211 status_packages["mpt-status"] ||= []
212 when "mpt2sas", "mpt3sas"
213 tools_packages << "sas2ircu"
214 status_packages["sas2ircu-status"] ||= []
216 tools_packages << "megactl"
217 status_packages["megaraid-status"] ||= []
219 tools_packages << "megacli"
220 status_packages["megaclisas-status"] ||= []
222 tools_packages << "arcconf"
223 status_packages["aacraid-status"] ||= []
225 tools_packages << "areca"
229 node[:block_device].each do |name, attributes|
230 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
232 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
233 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
235 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
236 status_packages["cciss-vol-status"] |= [File.basename(sg)]
242 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
243 if tools_packages.include?(tools_package)
244 package tools_package
246 package tools_package do
252 if tools_packages.include?("areca")
257 repository "https://git.openstreetmap.org/private/areca.git"
261 not_if { ENV["TEST_KITCHEN"] }
264 directory "/opt/areca" do
270 if status_packages.include?("cciss-vol-status")
271 template "/usr/local/bin/cciss-vol-statusd" do
272 source "cciss-vol-statusd.erb"
276 notifies :restart, "service[cciss-vol-statusd]"
279 systemd_service "cciss-vol-statusd" do
280 description "Check cciss_vol_status values in the background"
281 exec_start "/usr/local/bin/cciss-vol-statusd"
283 protect_system "full"
285 no_new_privileges true
286 notifies :restart, "service[cciss-vol-statusd]"
289 systemd_service "cciss-vol-statusd" do
293 template "/usr/local/bin/cciss-vol-statusd" do
298 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
299 if status_packages.include?(status_package)
300 package status_package
302 template "/etc/default/#{status_package}d" do
303 source "raid.default.erb"
307 variables :devices => status_packages[status_package]
310 service "#{status_package}d" do
311 action [:start, :enable]
312 supports :status => false, :restart => true, :reload => false
313 subscribes :restart, "template[/etc/default/#{status_package}d]"
316 package status_package do
320 file "/etc/default/#{status_package}d" do
326 disks = if node[:hardware][:disk]
327 node[:hardware][:disk][:disks]
332 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
334 nvmes = if node[:hardware][:pci]
335 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
340 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
342 if !intel_ssds.empty? || !intel_nvmes.empty?
345 intel_ssd_tool_version = "3.0.26"
347 remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
348 source "https://downloadmirror.intel.com/29720/eng/Intel_SSD_DCT_#{intel_ssd_tool_version}_Linux.zip"
351 execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
352 command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip isdct_#{intel_ssd_tool_version}.400-1_amd64.deb"
353 cwd Chef::Config[:file_cache_path]
356 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}.400-1_amd64.deb") }
359 dpkg_package "isdct" do
360 version "#{intel_ssd_tool_version}-1"
361 source "#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}.400-1_amd64.deb"
365 disks = disks.map do |disk|
366 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
368 if disk[:smart_device]
369 controller = node[:hardware][:disk][:controllers][disk[:controller]]
371 if controller && controller[:device]
372 device = controller[:device].sub("/dev/", "")
373 smart = disk[:smart_device]
375 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
376 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
377 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
378 elsif smart =~ /^.*,(\d+)$/
379 munin = "#{device}-#{Regexp.last_match(1)}"
380 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
381 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
384 device = disk[:device].sub("/dev/", "")
385 smart = disk[:smart_device]
387 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
388 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
391 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
392 device = Regexp.last_match(1)
395 device = disk[:device].sub("/dev/", "")
405 :hddtemp => munin.tr("-:", "_")
409 disks = disks.compact.uniq
411 if disks.count.positive?
412 package "smartmontools"
414 template "/etc/cron.daily/update-smart-drivedb" do
415 source "update-smart-drivedb.erb"
421 template "/usr/local/bin/smartd-mailer" do
422 source "smartd-mailer.erb"
428 template "/etc/smartd.conf" do
429 source "smartd.conf.erb"
433 variables :disks => disks
436 template "/etc/default/smartmontools" do
437 source "smartmontools.erb"
443 service "smartmontools" do
444 action [:enable, :start]
445 subscribes :reload, "template[/etc/smartd.conf]"
446 subscribes :restart, "template[/etc/default/smartmontools]"
449 # Don't try and do munin monitoring of disks behind
450 # an Areca controller as they only allow one thing to
451 # talk to the controller at a time and smartd will
452 # throw errors if it clashes with munin
453 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
456 munin_plugin "smart_#{disk[:munin]}" do
458 conf "munin.smart.erb"
459 conf_variables :disk => disk
463 template "/etc/prometheus/collectors/smart.devices" do
464 source "smart.devices.erb"
468 variables :disks => disks
471 prometheus_collector "smart" do
476 action [:stop, :disable]
480 if disks.count.positive?
481 munin_plugin "hddtemp_smartctl" do
482 conf "munin.hddtemp.erb"
483 conf_variables :disks => disks
486 munin_plugin "hddtemp_smartctl" do
488 conf "munin.hddtemp.erb"
492 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
493 disks.map { |d| "smart_#{d[:munin]}" }
495 plugins.each do |plugin|
496 munin_plugin plugin do
498 conf "munin.smart.erb"
502 if File.exist?("/etc/mdadm/mdadm.conf")
503 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
504 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
509 file "/etc/mdadm/mdadm.conf" do
518 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
522 template "/etc/modules" do
531 subscribes :start, "template[/etc/modules]"
534 if node[:hardware][:watchdog]
537 template "/etc/default/watchdog" do
538 source "watchdog.erb"
542 variables :module => node[:hardware][:watchdog]
545 service "watchdog" do
546 action [:enable, :start]
550 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
553 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
554 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
555 chip = format("coretemp-isa-%04d", cpu)
557 temps = if File.exist?("#{coretemp}/name")
558 Dir.glob("#{coretemp}/temp*_input").map do |temp|
559 File.basename(temp).sub("temp", "").sub("_input", "").to_i
562 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
563 File.basename(temp).sub("temp", "").sub("_input", "").to_i
568 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
572 temps.each_with_index do |temp, index|
573 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
577 execute "/etc/sensors.d/chef.conf" do
579 command "/usr/bin/sensors -s"
584 template "/etc/sensors.d/chef.conf" do
585 source "sensors.conf.erb"
589 notifies :run, "execute[/etc/sensors.d/chef.conf]"
593 if node[:hardware][:shm_size]
594 execute "remount-dev-shm" do
596 command "/bin/mount -o remount /dev/shm"
605 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
606 notifies :run, "execute[remount-dev-shm]"