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 package "hp-health" do
64 notifies :restart, "service[hp-health]"
65 only_if { node[:lsb][:release].to_f < 22.04 }
68 service "hp-health" do
69 action [:enable, :start]
70 supports :status => true, :restart => true
71 only_if { node[:lsb][:release].to_f < 22.04 }
74 if product.end_with?("Gen8", "Gen9")
77 notifies :restart, "service[hp-ams]"
81 action [:enable, :start]
82 supports :status => true, :restart => true
89 when "TYAN Computer Corporation"
96 package "open-vm-tools"
98 # Remove timeSync plugin completely
99 # https://github.com/vmware/open-vm-tools/issues/302
100 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
102 notifies :restart, "service[open-vm-tools]"
105 # Attempt to tell Host we are not interested in timeSync
106 execute "vmware-toolbox-cmd-timesync-disable" do
107 command "/usr/bin/vmware-toolbox-cmd timesync disable"
111 service "open-vm-tools" do
112 action [:enable, :start]
113 supports :status => true, :restart => true
117 units.sort.uniq.each do |unit|
118 service "serial-getty@ttyS#{unit}" do
119 action [:enable, :start]
123 # if we need a different / special kernel version to make the hardware
124 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
125 # ensure that we have the package installed. the grub template will
126 # make sure that this is the default on boot.
127 if node[:hardware][:grub][:kernel]
128 kernel_version = node[:hardware][:grub][:kernel]
130 package "linux-image-#{kernel_version}-generic"
131 package "linux-image-extra-#{kernel_version}-generic"
132 package "linux-headers-#{kernel_version}-generic"
133 package "linux-tools-#{kernel_version}-generic"
135 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
136 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
137 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
142 if File.exist?("/etc/default/grub")
143 execute "update-grub" do
145 command "/usr/sbin/update-grub"
149 template "/etc/default/grub" do
154 variables :units => units, :entry => grub_entry
155 notifies :run, "execute[update-grub]"
159 execute "update-initramfs" do
161 command "update-initramfs -u -k all"
166 template "/etc/initramfs-tools/conf.d/mdadm" do
167 source "initramfs-mdadm.erb"
171 notifies :run, "execute[update-initramfs]"
176 action [:enable, :start]
179 if node[:kernel][:modules].include?("ipmi_si")
181 package "freeipmi-tools"
183 template "/etc/prometheus/ipmi_local.yml" do
184 source "ipmi_local.yml.erb"
190 prometheus_exporter "ipmi" do
192 options "--config.file=/etc/prometheus/ipmi_local.yml"
193 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
199 service "irqbalance" do
200 action [:start, :enable]
201 supports :status => false, :restart => true, :reload => false
207 action [:start, :enable]
208 supports :status => true, :restart => true, :reload => true
211 ohai_plugin "lldp" do
212 template "lldp.rb.erb"
218 if node[:virtualization][:role] != "guest" ||
219 (node[:virtualization][:system] != "lxc" &&
220 node[:virtualization][:system] != "lxd" &&
221 node[:virtualization][:system] != "openvz")
223 node[:kernel][:modules].each_key do |modname|
226 tools_packages << "ssacli"
227 status_packages["cciss-vol-status"] ||= []
229 tools_packages << "ssacli"
230 status_packages["cciss-vol-status"] ||= []
232 tools_packages << "lsiutil"
233 status_packages["mpt-status"] ||= []
234 when "mpt2sas", "mpt3sas"
235 tools_packages << "sas2ircu"
236 status_packages["sas2ircu-status"] ||= []
238 tools_packages << "megactl"
239 status_packages["megaraid-status"] ||= []
241 tools_packages << "megacli"
242 status_packages["megaclisas-status"] ||= [] if node[:lsb][:release].to_f < 22.04
244 tools_packages << "arcconf"
245 status_packages["aacraid-status"] ||= []
247 tools_packages << "areca"
251 node[:block_device].each do |name, attributes|
252 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
254 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
255 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
257 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
258 status_packages["cciss-vol-status"] |= [File.basename(sg)]
264 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
265 if tools_packages.include?(tools_package)
266 package tools_package
268 package tools_package do
274 if tools_packages.include?("areca")
279 repository "https://git.openstreetmap.org/private/areca.git"
286 directory "/opt/areca" do
292 if status_packages.include?("cciss-vol-status")
293 template "/usr/local/bin/cciss-vol-statusd" do
294 source "cciss-vol-statusd.erb"
298 notifies :restart, "service[cciss-vol-statusd]"
301 systemd_service "cciss-vol-statusd" do
302 description "Check cciss_vol_status values in the background"
303 exec_start "/usr/local/bin/cciss-vol-statusd"
305 protect_system "full"
307 no_new_privileges true
308 notifies :restart, "service[cciss-vol-statusd]"
311 systemd_service "cciss-vol-statusd" do
315 template "/usr/local/bin/cciss-vol-statusd" do
320 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
321 if status_packages.include?(status_package)
322 package status_package
324 template "/etc/default/#{status_package}d" do
325 source "raid.default.erb"
329 variables :devices => status_packages[status_package]
332 service "#{status_package}d" do
333 action [:start, :enable]
334 supports :status => false, :restart => true, :reload => false
335 subscribes :restart, "template[/etc/default/#{status_package}d]"
338 package status_package do
342 file "/etc/default/#{status_package}d" do
348 disks = if node[:hardware][:disk]
349 node[:hardware][:disk][:disks]
354 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
356 nvmes = if node[:hardware][:pci]
357 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
366 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
368 if !intel_ssds.empty? || !intel_nvmes.empty?
371 intel_mas_tool_version = "1.10"
372 intel_mas_package_version = "#{intel_mas_tool_version}.155-0"
374 remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
375 source "https://downloadmirror.intel.com/646992/Intel_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}-v2.zip"
378 execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
379 command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
380 cwd Chef::Config[:file_cache_path]
383 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
386 dpkg_package "intelmas" do
387 version "#{intel_mas_package_version}"
388 source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
391 dpkg_package "isdct" do
396 disks = disks.map do |disk|
397 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
399 if disk[:smart_device]
400 controller = node[:hardware][:disk][:controllers][disk[:controller]]
402 if controller && controller[:device]
403 device = controller[:device].sub("/dev/", "")
404 smart = disk[:smart_device]
406 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
407 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
408 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
409 elsif smart =~ /^.*,(\d+)$/
410 munin = "#{device}-#{Regexp.last_match(1)}"
411 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
412 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
415 device = disk[:device].sub("/dev/", "")
416 smart = disk[:smart_device]
418 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
419 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
422 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
423 device = Regexp.last_match(1)
426 device = disk[:device].sub("/dev/", "")
436 :hddtemp => munin.tr("-:", "_")
440 disks = disks.compact.uniq
442 if disks.count.positive?
443 package "smartmontools"
445 template "/etc/cron.daily/update-smart-drivedb" do
446 source "update-smart-drivedb.erb"
452 template "/usr/local/bin/smartd-mailer" do
453 source "smartd-mailer.erb"
459 template "/etc/smartd.conf" do
460 source "smartd.conf.erb"
464 variables :disks => disks
467 template "/etc/default/smartmontools" do
468 source "smartmontools.erb"
474 service "smartmontools" do
475 action [:enable, :start]
476 subscribes :reload, "template[/etc/smartd.conf]"
477 subscribes :restart, "template[/etc/default/smartmontools]"
480 template "/etc/prometheus/collectors/smart.devices" do
481 source "smart.devices.erb"
485 variables :disks => disks
488 prometheus_collector "smart" do
492 # Don't try and do munin monitoring of disks behind
493 # an Areca controller as they only allow one thing to
494 # talk to the controller at a time and smartd will
495 # throw errors if it clashes with munin
496 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
499 munin_plugin "smart_#{disk[:munin]}" do
501 conf "munin.smart.erb"
502 conf_variables :disk => disk
507 action [:stop, :disable]
511 if disks.count.positive?
512 munin_plugin "hddtemp_smartctl" do
513 conf "munin.hddtemp.erb"
514 conf_variables :disks => disks
517 munin_plugin "hddtemp_smartctl" do
519 conf "munin.hddtemp.erb"
523 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
524 disks.map { |d| "smart_#{d[:munin]}" }
526 plugins.each do |plugin|
527 munin_plugin plugin do
529 conf "munin.smart.erb"
533 if File.exist?("/etc/mdadm/mdadm.conf")
534 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
535 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
540 file "/etc/mdadm/mdadm.conf" do
549 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
553 file "/etc/modules" do
557 node[:hardware][:modules].each do |module_name|
558 kernel_module module_name do
564 node[:hardware][:blacklisted_modules].each do |module_name|
565 kernel_module module_name do
570 if node[:hardware][:watchdog]
573 template "/etc/default/watchdog" do
574 source "watchdog.erb"
578 variables :module => node[:hardware][:watchdog]
581 service "watchdog" do
582 action [:enable, :start]
586 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
589 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
590 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
591 chip = format("coretemp-isa-%04d", cpu)
593 temps = if File.exist?("#{coretemp}/name")
594 Dir.glob("#{coretemp}/temp*_input").map do |temp|
595 File.basename(temp).sub("temp", "").sub("_input", "").to_i
598 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
599 File.basename(temp).sub("temp", "").sub("_input", "").to_i
604 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
608 temps.each_with_index do |temp, index|
609 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
613 execute "/etc/sensors.d/chef.conf" do
615 command "/usr/bin/sensors -s"
620 template "/etc/sensors.d/chef.conf" do
621 source "sensors.conf.erb"
625 notifies :run, "execute[/etc/sensors.d/chef.conf]"
629 if node[:hardware][:shm_size]
630 execute "remount-dev-shm" do
632 command "/bin/mount -o remount /dev/shm"
641 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
642 notifies :run, "execute[remount-dev-shm]"