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.
21 include_recipe "munin"
22 include_recipe "prometheus"
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") || node[:roles].include?("prgmr")
59 include_recipe "apt::management-component-pack"
63 execute "update-ilo" do
65 command "/usr/sbin/hponcfg -f /etc/ilo-defaults.xml"
69 template "/etc/ilo-defaults.xml" do
70 source "ilo-defaults.xml.erb"
74 notifies :run, "execute[update-ilo]"
77 package "hp-health" do
79 notifies :restart, "service[hp-health]"
80 only_if { node[:lsb][:release].to_f < 22.04 }
83 service "hp-health" do
84 action [:enable, :start]
85 supports :status => true, :restart => true
86 only_if { node[:lsb][:release].to_f < 22.04 }
89 if product.end_with?("Gen8", "Gen9")
92 notifies :restart, "service[hp-ams]"
96 action [:enable, :start]
97 supports :status => true, :restart => true
99 elsif product.end_with?("Gen10")
102 notifies :restart, "service[amsd]"
106 action [:enable, :start]
107 supports :status => true, :restart => true
111 units << if product.end_with?("Gen10")
118 when "TYAN Computer Corporation"
125 package "open-vm-tools"
127 # Remove timeSync plugin completely
128 # https://github.com/vmware/open-vm-tools/issues/302
129 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
131 notifies :restart, "service[open-vm-tools]"
134 # Attempt to tell Host we are not interested in timeSync
135 execute "vmware-toolbox-cmd-timesync-disable" do
136 command "/usr/bin/vmware-toolbox-cmd timesync disable"
140 service "open-vm-tools" do
141 action [:enable, :start]
142 supports :status => true, :restart => true
146 units.sort.uniq.each do |unit|
147 service "serial-getty@ttyS#{unit}" do
148 action [:enable, :start]
153 # if we need a different / special kernel version to make the hardware
154 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
155 # ensure that we have the package installed. the grub template will
156 # make sure that this is the default on boot.
157 if node[:hardware][:grub][:kernel]
158 kernel_version = node[:hardware][:grub][:kernel]
160 package "linux-image-#{kernel_version}-generic"
161 package "linux-image-extra-#{kernel_version}-generic"
162 package "linux-headers-#{kernel_version}-generic"
163 package "linux-tools-#{kernel_version}-generic"
165 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
166 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
167 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
172 if File.exist?("/etc/default/grub")
173 execute "update-grub" do
175 command "/usr/sbin/update-grub"
179 template "/etc/default/grub" do
184 variables :units => units, :entry => grub_entry
185 notifies :run, "execute[update-grub]"
189 execute "update-initramfs" do
191 command "update-initramfs -u -k all"
196 template "/etc/initramfs-tools/conf.d/mdadm" do
197 source "initramfs-mdadm.erb"
201 notifies :run, "execute[update-initramfs]"
206 action [:enable, :start]
209 if node[:kernel][:modules].include?("ipmi_si")
211 package "freeipmi-tools"
213 template "/etc/prometheus/ipmi_local.yml" do
214 source "ipmi_local.yml.erb"
220 prometheus_exporter "ipmi" do
223 private_devices false
225 system_call_filter ["@system-service", "@raw-io"]
226 options "--config.file=/etc/prometheus/ipmi_local.yml"
227 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
233 service "irqbalance" do
234 action [:start, :enable]
235 supports :status => false, :restart => true, :reload => false
241 action [:start, :enable]
242 supports :status => true, :restart => true, :reload => true
245 ohai_plugin "lldp" do
246 template "lldp.rb.erb"
254 service "rasdaemon" do
255 action [:enable, :start]
258 prometheus_exporter "rasdaemon" do
266 if node[:virtualization][:role] != "guest" ||
267 (node[:virtualization][:system] != "lxc" &&
268 node[:virtualization][:system] != "lxd" &&
269 node[:virtualization][:system] != "openvz")
271 node[:kernel][:modules].each_key do |modname|
274 tools_packages << "ssacli"
275 status_packages["cciss-vol-status"] ||= []
277 tools_packages << "ssacli"
278 status_packages["cciss-vol-status"] ||= []
280 tools_packages << "lsiutil"
281 status_packages["mpt-status"] ||= []
282 when "mpt2sas", "mpt3sas"
283 tools_packages << "sas2ircu"
284 status_packages["sas2ircu-status"] ||= []
286 tools_packages << "megacli"
287 status_packages["megaclisas-status"] ||= []
289 tools_packages << "arcconf"
290 status_packages["aacraid-status"] ||= []
292 tools_packages << "areca"
296 node[:block_device].each do |name, attributes|
297 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
299 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
300 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
302 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
303 status_packages["cciss-vol-status"] |= [File.basename(sg)]
309 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
310 if tools_packages.include?(tools_package)
311 package tools_package
313 package tools_package do
319 if tools_packages.include?("areca")
324 repository "https://git.openstreetmap.org/private/areca.git"
331 directory "/opt/areca" do
337 include_recipe "apt::hwraid" unless status_packages.empty?
339 if status_packages.include?("cciss-vol-status")
340 template "/usr/local/bin/cciss-vol-statusd" do
341 source "cciss-vol-statusd.erb"
345 notifies :restart, "service[cciss-vol-statusd]"
348 systemd_service "cciss-vol-statusd" do
349 description "Check cciss_vol_status values in the background"
350 exec_start "/usr/local/bin/cciss-vol-statusd"
353 protect_system "full"
355 no_new_privileges true
356 notifies :restart, "service[cciss-vol-statusd]"
359 systemd_service "cciss-vol-statusd" do
363 template "/usr/local/bin/cciss-vol-statusd" do
368 %w[cciss-vol-status mpt-status sas2ircu-status megaclisas-status aacraid-status].each do |status_package|
369 if status_packages.include?(status_package)
370 package status_package
372 template "/etc/default/#{status_package}d" do
373 source "raid.default.erb"
377 variables :devices => status_packages[status_package]
380 service "#{status_package}d" do
381 action [:start, :enable]
382 supports :status => false, :restart => true, :reload => false
383 subscribes :restart, "template[/etc/default/#{status_package}d]"
386 package status_package do
390 file "/etc/default/#{status_package}d" do
396 disks = if node[:hardware][:disk]
397 node[:hardware][:disk][:disks]
402 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
404 nvmes = if node[:hardware][:pci]
405 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
414 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
416 if !intel_ssds.empty? || !intel_nvmes.empty?
419 sst_tool_version = "1.3"
420 sst_package_version = "#{sst_tool_version}.208-0"
422 # remote_file "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
423 # source "https://downloadmirror.intel.com/743764/SST_CLI_Linux_#{sst_tool_version}.zip"
426 execute "#{Chef::Config[:file_cache_path]}/SST_CLI_Linux_#{sst_tool_version}.zip" do
427 command "unzip SST_CLI_Linux_#{sst_tool_version}.zip sst_#{sst_package_version}_amd64.deb"
428 cwd Chef::Config[:file_cache_path]
431 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb") }
434 dpkg_package "sst" do
435 version "#{sst_package_version}"
436 source "#{Chef::Config[:file_cache_path]}/sst_#{sst_package_version}_amd64.deb"
439 dpkg_package "intelmas" do
444 disks = disks.map do |disk|
445 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
447 if disk[:smart_device]
448 controller = node[:hardware][:disk][:controllers][disk[:controller]]
450 if controller && controller[:device]
451 device = controller[:device].sub("/dev/", "")
452 smart = disk[:smart_device]
454 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
455 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
456 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
457 elsif smart =~ /^.*,(\d+)$/
458 munin = "#{device}-#{Regexp.last_match(1)}"
459 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
460 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
463 device = disk[:device].sub("/dev/", "")
464 smart = disk[:smart_device]
466 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
467 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
470 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
471 device = Regexp.last_match(1)
474 device = disk[:device].sub("/dev/", "")
484 :hddtemp => munin.tr("-:", "_")
488 disks = disks.compact.uniq
490 if disks.count.positive?
491 package "smartmontools"
493 template "/etc/cron.daily/update-smart-drivedb" do
494 source "update-smart-drivedb.erb"
500 template "/usr/local/bin/smartd-mailer" do
501 source "smartd-mailer.erb"
507 template "/etc/smartd.conf" do
508 source "smartd.conf.erb"
512 variables :disks => disks
515 template "/etc/default/smartmontools" do
516 source "smartmontools.erb"
522 service "smartmontools" do
523 action [:enable, :start]
524 subscribes :reload, "template[/etc/smartd.conf]"
525 subscribes :restart, "template[/etc/default/smartmontools]"
528 template "/etc/prometheus/collectors/smart.devices" do
529 source "smart.devices.erb"
533 variables :disks => disks
536 prometheus_collector "smart" do
539 capability_bounding_set %w[CAP_SYS_ADMIN CAP_SYS_RAWIO]
540 private_devices false
545 # Don't try and do munin monitoring of disks behind
546 # an Areca controller as they only allow one thing to
547 # talk to the controller at a time and smartd will
548 # throw errors if it clashes with munin
549 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
552 munin_plugin "smart_#{disk[:munin]}" do
554 conf "munin.smart.erb"
555 conf_variables :disk => disk
560 action [:stop, :disable]
564 if disks.count.positive?
565 munin_plugin "hddtemp_smartctl" do
566 conf "munin.hddtemp.erb"
567 conf_variables :disks => disks
570 munin_plugin "hddtemp_smartctl" do
572 conf "munin.hddtemp.erb"
576 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
577 disks.map { |d| "smart_#{d[:munin]}" }
579 plugins.each do |plugin|
580 munin_plugin plugin do
582 conf "munin.smart.erb"
586 if File.exist?("/etc/mdadm/mdadm.conf")
587 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
588 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
593 file "/etc/mdadm/mdadm.conf" do
600 service "mdmonitor" do
602 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
606 file "/etc/modules" do
610 node[:hardware][:modules].each do |module_name|
611 kernel_module module_name do
617 node[:hardware][:blacklisted_modules].each do |module_name|
618 kernel_module module_name do
623 if node[:hardware][:watchdog]
626 template "/etc/default/watchdog" do
627 source "watchdog.erb"
631 variables :module => node[:hardware][:watchdog]
634 service "watchdog" do
635 action [:enable, :start]
639 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
642 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
643 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
644 chip = format("coretemp-isa-%04d", cpu)
646 temps = if File.exist?("#{coretemp}/name")
647 Dir.glob("#{coretemp}/temp*_input").map do |temp|
648 File.basename(temp).sub("temp", "").sub("_input", "").to_i
651 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
652 File.basename(temp).sub("temp", "").sub("_input", "").to_i
657 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
661 temps.each_with_index do |temp, index|
662 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
666 execute "/etc/sensors.d/chef.conf" do
668 command "/usr/bin/sensors -s"
673 template "/etc/sensors.d/chef.conf" do
674 source "sensors.conf.erb"
678 notifies :run, "execute[/etc/sensors.d/chef.conf]"
682 if node[:hardware][:shm_size]
683 execute "remount-dev-shm" do
685 command "/bin/mount -o remount /dev/shm"
694 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
695 notifies :run, "execute[remount-dev-shm]"
699 prometheus_collector "ohai" do
703 capability_bounding_set "CAP_SYS_ADMIN"
704 private_devices false
707 protect_kernel_modules false