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") || node[:roles].include?("prgmr")
62 execute "update-ilo" do
64 command "/usr/sbin/hponcfg -f /etc/ilo-defaults.xml"
67 template "/etc/ilo-defaults.xml" do
68 source "ilo-defaults.xml.erb"
72 notifies :run, "execute[update-ilo]"
75 package "hp-health" do
77 notifies :restart, "service[hp-health]"
78 only_if { node[:lsb][:release].to_f < 22.04 }
81 service "hp-health" do
82 action [:enable, :start]
83 supports :status => true, :restart => true
84 only_if { node[:lsb][:release].to_f < 22.04 }
87 if product.end_with?("Gen8", "Gen9")
90 notifies :restart, "service[hp-ams]"
94 action [:enable, :start]
95 supports :status => true, :restart => true
102 when "TYAN Computer Corporation"
109 package "open-vm-tools"
111 # Remove timeSync plugin completely
112 # https://github.com/vmware/open-vm-tools/issues/302
113 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
115 notifies :restart, "service[open-vm-tools]"
118 # Attempt to tell Host we are not interested in timeSync
119 execute "vmware-toolbox-cmd-timesync-disable" do
120 command "/usr/bin/vmware-toolbox-cmd timesync disable"
124 service "open-vm-tools" do
125 action [:enable, :start]
126 supports :status => true, :restart => true
130 units.sort.uniq.each do |unit|
131 service "serial-getty@ttyS#{unit}" do
132 action [:enable, :start]
136 # if we need a different / special kernel version to make the hardware
137 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
138 # ensure that we have the package installed. the grub template will
139 # make sure that this is the default on boot.
140 if node[:hardware][:grub][:kernel]
141 kernel_version = node[:hardware][:grub][:kernel]
143 package "linux-image-#{kernel_version}-generic"
144 package "linux-image-extra-#{kernel_version}-generic"
145 package "linux-headers-#{kernel_version}-generic"
146 package "linux-tools-#{kernel_version}-generic"
148 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
149 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
150 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
155 if File.exist?("/etc/default/grub")
156 execute "update-grub" do
158 command "/usr/sbin/update-grub"
162 template "/etc/default/grub" do
167 variables :units => units, :entry => grub_entry
168 notifies :run, "execute[update-grub]"
172 execute "update-initramfs" do
174 command "update-initramfs -u -k all"
179 template "/etc/initramfs-tools/conf.d/mdadm" do
180 source "initramfs-mdadm.erb"
184 notifies :run, "execute[update-initramfs]"
189 action [:enable, :start]
192 if node[:kernel][:modules].include?("ipmi_si")
194 package "freeipmi-tools"
196 template "/etc/prometheus/ipmi_local.yml" do
197 source "ipmi_local.yml.erb"
203 prometheus_exporter "ipmi" do
205 options "--config.file=/etc/prometheus/ipmi_local.yml"
206 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
212 service "irqbalance" do
213 action [:start, :enable]
214 supports :status => false, :restart => true, :reload => false
220 action [:start, :enable]
221 supports :status => true, :restart => true, :reload => true
224 ohai_plugin "lldp" do
225 template "lldp.rb.erb"
231 if node[:virtualization][:role] != "guest" ||
232 (node[:virtualization][:system] != "lxc" &&
233 node[:virtualization][:system] != "lxd" &&
234 node[:virtualization][:system] != "openvz")
236 node[:kernel][:modules].each_key do |modname|
239 tools_packages << "ssacli"
240 status_packages["cciss-vol-status"] ||= []
242 tools_packages << "ssacli"
243 status_packages["cciss-vol-status"] ||= []
245 tools_packages << "lsiutil"
246 status_packages["mpt-status"] ||= []
247 when "mpt2sas", "mpt3sas"
248 tools_packages << "sas2ircu"
249 status_packages["sas2ircu-status"] ||= []
251 tools_packages << "megacli"
252 status_packages["megaclisas-status"] ||= []
254 tools_packages << "arcconf"
255 status_packages["aacraid-status"] ||= []
257 tools_packages << "areca"
261 node[:block_device].each do |name, attributes|
262 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
264 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
265 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
267 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
268 status_packages["cciss-vol-status"] |= [File.basename(sg)]
274 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
275 if tools_packages.include?(tools_package)
276 package tools_package
278 package tools_package do
284 if tools_packages.include?("areca")
289 repository "https://git.openstreetmap.org/private/areca.git"
296 directory "/opt/areca" do
302 if status_packages.include?("cciss-vol-status")
303 template "/usr/local/bin/cciss-vol-statusd" do
304 source "cciss-vol-statusd.erb"
308 notifies :restart, "service[cciss-vol-statusd]"
311 systemd_service "cciss-vol-statusd" do
312 description "Check cciss_vol_status values in the background"
313 exec_start "/usr/local/bin/cciss-vol-statusd"
315 protect_system "full"
317 no_new_privileges true
318 notifies :restart, "service[cciss-vol-statusd]"
321 systemd_service "cciss-vol-statusd" do
325 template "/usr/local/bin/cciss-vol-statusd" do
330 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
331 if status_packages.include?(status_package)
332 package status_package
334 template "/etc/default/#{status_package}d" do
335 source "raid.default.erb"
339 variables :devices => status_packages[status_package]
342 service "#{status_package}d" do
343 action [:start, :enable]
344 supports :status => false, :restart => true, :reload => false
345 subscribes :restart, "template[/etc/default/#{status_package}d]"
348 package status_package do
352 file "/etc/default/#{status_package}d" do
358 disks = if node[:hardware][:disk]
359 node[:hardware][:disk][:disks]
364 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
366 nvmes = if node[:hardware][:pci]
367 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
376 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
378 if !intel_ssds.empty? || !intel_nvmes.empty?
381 intel_mas_tool_version = "1.10"
382 intel_mas_package_version = "#{intel_mas_tool_version}.155-0"
384 remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
385 source "https://downloadmirror.intel.com/646992/Intel_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}-v2.zip"
388 execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
389 command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
390 cwd Chef::Config[:file_cache_path]
393 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
396 dpkg_package "intelmas" do
397 version "#{intel_mas_package_version}"
398 source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
401 dpkg_package "isdct" do
406 disks = disks.map do |disk|
407 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
409 if disk[:smart_device]
410 controller = node[:hardware][:disk][:controllers][disk[:controller]]
412 if controller && controller[:device]
413 device = controller[:device].sub("/dev/", "")
414 smart = disk[:smart_device]
416 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
417 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
418 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
419 elsif smart =~ /^.*,(\d+)$/
420 munin = "#{device}-#{Regexp.last_match(1)}"
421 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
422 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
425 device = disk[:device].sub("/dev/", "")
426 smart = disk[:smart_device]
428 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
429 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
432 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
433 device = Regexp.last_match(1)
436 device = disk[:device].sub("/dev/", "")
446 :hddtemp => munin.tr("-:", "_")
450 disks = disks.compact.uniq
452 if disks.count.positive?
453 package "smartmontools"
455 template "/etc/cron.daily/update-smart-drivedb" do
456 source "update-smart-drivedb.erb"
462 template "/usr/local/bin/smartd-mailer" do
463 source "smartd-mailer.erb"
469 template "/etc/smartd.conf" do
470 source "smartd.conf.erb"
474 variables :disks => disks
477 template "/etc/default/smartmontools" do
478 source "smartmontools.erb"
484 service "smartmontools" do
485 action [:enable, :start]
486 subscribes :reload, "template[/etc/smartd.conf]"
487 subscribes :restart, "template[/etc/default/smartmontools]"
490 template "/etc/prometheus/collectors/smart.devices" do
491 source "smart.devices.erb"
495 variables :disks => disks
498 prometheus_collector "smart" do
502 # Don't try and do munin monitoring of disks behind
503 # an Areca controller as they only allow one thing to
504 # talk to the controller at a time and smartd will
505 # throw errors if it clashes with munin
506 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
509 munin_plugin "smart_#{disk[:munin]}" do
511 conf "munin.smart.erb"
512 conf_variables :disk => disk
517 action [:stop, :disable]
521 if disks.count.positive?
522 munin_plugin "hddtemp_smartctl" do
523 conf "munin.hddtemp.erb"
524 conf_variables :disks => disks
527 munin_plugin "hddtemp_smartctl" do
529 conf "munin.hddtemp.erb"
533 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
534 disks.map { |d| "smart_#{d[:munin]}" }
536 plugins.each do |plugin|
537 munin_plugin plugin do
539 conf "munin.smart.erb"
543 if File.exist?("/etc/mdadm/mdadm.conf")
544 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
545 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
550 file "/etc/mdadm/mdadm.conf" do
559 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
563 file "/etc/modules" do
567 node[:hardware][:modules].each do |module_name|
568 kernel_module module_name do
574 node[:hardware][:blacklisted_modules].each do |module_name|
575 kernel_module module_name do
580 if node[:hardware][:watchdog]
583 template "/etc/default/watchdog" do
584 source "watchdog.erb"
588 variables :module => node[:hardware][:watchdog]
591 service "watchdog" do
592 action [:enable, :start]
596 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
599 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
600 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
601 chip = format("coretemp-isa-%04d", cpu)
603 temps = if File.exist?("#{coretemp}/name")
604 Dir.glob("#{coretemp}/temp*_input").map do |temp|
605 File.basename(temp).sub("temp", "").sub("_input", "").to_i
608 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
609 File.basename(temp).sub("temp", "").sub("_input", "").to_i
614 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
618 temps.each_with_index do |temp, index|
619 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
623 execute "/etc/sensors.d/chef.conf" do
625 command "/usr/bin/sensors -s"
630 template "/etc/sensors.d/chef.conf" do
631 source "sensors.conf.erb"
635 notifies :run, "execute[/etc/sensors.d/chef.conf]"
639 if node[:hardware][:shm_size]
640 execute "remount-dev-shm" do
642 command "/bin/mount -o remount /dev/shm"
651 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
652 notifies :run, "execute[remount-dev-shm]"
656 prometheus_collector "ohai" do