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]"
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"
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 if node[:kernel][:modules].include?("ipmi_si")
179 package "freeipmi-tools"
181 template "/etc/prometheus/ipmi_local.yml" do
182 source "ipmi_local.yml.erb"
188 prometheus_exporter "ipmi" do
190 options "--config.file=/etc/prometheus/ipmi_local.yml"
191 subscribes :restart, "template[/etc/prometheus/ipmi_local.yml]"
197 service "irqbalance" do
198 action [:start, :enable]
199 supports :status => false, :restart => true, :reload => false
205 action [:start, :enable]
206 supports :status => true, :restart => true, :reload => true
209 ohai_plugin "lldp" do
210 template "lldp.rb.erb"
216 if node[:virtualization][:role] != "guest" ||
217 (node[:virtualization][:system] != "lxc" &&
218 node[:virtualization][:system] != "lxd" &&
219 node[:virtualization][:system] != "openvz")
221 node[:kernel][:modules].each_key do |modname|
224 tools_packages << "ssacli"
225 status_packages["cciss-vol-status"] ||= []
227 tools_packages << "ssacli"
228 status_packages["cciss-vol-status"] ||= []
230 tools_packages << "lsiutil"
231 status_packages["mpt-status"] ||= []
232 when "mpt2sas", "mpt3sas"
233 tools_packages << "sas2ircu"
234 status_packages["sas2ircu-status"] ||= []
236 tools_packages << "megactl"
237 status_packages["megaraid-status"] ||= []
239 tools_packages << "megacli"
240 status_packages["megaclisas-status"] ||= []
242 tools_packages << "arcconf"
243 status_packages["aacraid-status"] ||= []
245 tools_packages << "areca"
249 node[:block_device].each do |name, attributes|
250 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
252 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
253 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
255 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
256 status_packages["cciss-vol-status"] |= [File.basename(sg)]
262 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
263 if tools_packages.include?(tools_package)
264 package tools_package
266 package tools_package do
272 if tools_packages.include?("areca")
277 repository "https://git.openstreetmap.org/private/areca.git"
284 directory "/opt/areca" do
290 if status_packages.include?("cciss-vol-status")
291 template "/usr/local/bin/cciss-vol-statusd" do
292 source "cciss-vol-statusd.erb"
296 notifies :restart, "service[cciss-vol-statusd]"
299 systemd_service "cciss-vol-statusd" do
300 description "Check cciss_vol_status values in the background"
301 exec_start "/usr/local/bin/cciss-vol-statusd"
303 protect_system "full"
305 no_new_privileges true
306 notifies :restart, "service[cciss-vol-statusd]"
309 systemd_service "cciss-vol-statusd" do
313 template "/usr/local/bin/cciss-vol-statusd" do
318 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
319 if status_packages.include?(status_package)
320 package status_package
322 template "/etc/default/#{status_package}d" do
323 source "raid.default.erb"
327 variables :devices => status_packages[status_package]
330 service "#{status_package}d" do
331 action [:start, :enable]
332 supports :status => false, :restart => true, :reload => false
333 subscribes :restart, "template[/etc/default/#{status_package}d]"
336 package status_package do
340 file "/etc/default/#{status_package}d" do
346 disks = if node[:hardware][:disk]
347 node[:hardware][:disk][:disks]
352 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
354 nvmes = if node[:hardware][:pci]
355 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
364 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
366 if !intel_ssds.empty? || !intel_nvmes.empty?
369 intel_mas_tool_version = "1.10"
370 intel_mas_package_version = "#{intel_mas_tool_version}.155-0"
372 remote_file "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
373 source "https://downloadmirror.intel.com/646992/Intel_MAS_CLI_Tool_Linux_#{intel_mas_tool_version}-v2.zip"
376 execute "#{Chef::Config[:file_cache_path]}/Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip" do
377 command "unzip Intel_MAS_CLI_Tool_#{intel_mas_tool_version}_Linux.zip intelmas_#{intel_mas_package_version}_amd64.deb"
378 cwd Chef::Config[:file_cache_path]
381 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb") }
384 dpkg_package "intelmas" do
385 version "#{intel_mas_package_version}"
386 source "#{Chef::Config[:file_cache_path]}/intelmas_#{intel_mas_package_version}_amd64.deb"
389 dpkg_package "isdct" do
394 disks = disks.map do |disk|
395 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
397 if disk[:smart_device]
398 controller = node[:hardware][:disk][:controllers][disk[:controller]]
400 if controller && controller[:device]
401 device = controller[:device].sub("/dev/", "")
402 smart = disk[:smart_device]
404 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
405 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
406 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
407 elsif smart =~ /^.*,(\d+)$/
408 munin = "#{device}-#{Regexp.last_match(1)}"
409 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
410 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
413 device = disk[:device].sub("/dev/", "")
414 smart = disk[:smart_device]
416 if smart =~ /^.*,(\d+),(\d+),(\d+)$/
417 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}:#{Regexp.last_match(3)}"
420 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
421 device = Regexp.last_match(1)
424 device = disk[:device].sub("/dev/", "")
434 :hddtemp => munin.tr("-:", "_")
438 disks = disks.compact.uniq
440 if disks.count.positive?
441 package "smartmontools"
443 template "/etc/cron.daily/update-smart-drivedb" do
444 source "update-smart-drivedb.erb"
450 template "/usr/local/bin/smartd-mailer" do
451 source "smartd-mailer.erb"
457 template "/etc/smartd.conf" do
458 source "smartd.conf.erb"
462 variables :disks => disks
465 template "/etc/default/smartmontools" do
466 source "smartmontools.erb"
472 service "smartmontools" do
473 action [:enable, :start]
474 subscribes :reload, "template[/etc/smartd.conf]"
475 subscribes :restart, "template[/etc/default/smartmontools]"
478 template "/etc/prometheus/collectors/smart.devices" do
479 source "smart.devices.erb"
483 variables :disks => disks
486 prometheus_collector "smart" do
490 # Don't try and do munin monitoring of disks behind
491 # an Areca controller as they only allow one thing to
492 # talk to the controller at a time and smartd will
493 # throw errors if it clashes with munin
494 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
497 munin_plugin "smart_#{disk[:munin]}" do
499 conf "munin.smart.erb"
500 conf_variables :disk => disk
505 action [:stop, :disable]
509 if disks.count.positive?
510 munin_plugin "hddtemp_smartctl" do
511 conf "munin.hddtemp.erb"
512 conf_variables :disks => disks
515 munin_plugin "hddtemp_smartctl" do
517 conf "munin.hddtemp.erb"
521 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
522 disks.map { |d| "smart_#{d[:munin]}" }
524 plugins.each do |plugin|
525 munin_plugin plugin do
527 conf "munin.smart.erb"
531 if File.exist?("/etc/mdadm/mdadm.conf")
532 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
533 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
538 file "/etc/mdadm/mdadm.conf" do
547 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
551 file "/etc/modules" do
555 node[:hardware][:modules].each do |module_name|
556 kernel_module module_name do
562 node[:hardware][:blacklisted_modules].each do |module_name|
563 kernel_module module_name do
568 if node[:hardware][:watchdog]
571 template "/etc/default/watchdog" do
572 source "watchdog.erb"
576 variables :module => node[:hardware][:watchdog]
579 service "watchdog" do
580 action [:enable, :start]
584 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
587 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
588 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
589 chip = format("coretemp-isa-%04d", cpu)
591 temps = if File.exist?("#{coretemp}/name")
592 Dir.glob("#{coretemp}/temp*_input").map do |temp|
593 File.basename(temp).sub("temp", "").sub("_input", "").to_i
596 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
597 File.basename(temp).sub("temp", "").sub("_input", "").to_i
602 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
606 temps.each_with_index do |temp, index|
607 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
611 execute "/etc/sensors.d/chef.conf" do
613 command "/usr/bin/sensors -s"
618 template "/etc/sensors.d/chef.conf" do
619 source "sensors.conf.erb"
623 notifies :run, "execute[/etc/sensors.d/chef.conf]"
627 if node[:hardware][:shm_size]
628 execute "remount-dev-shm" do
630 command "/bin/mount -o remount /dev/shm"
639 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
640 notifies :run, "execute[remount-dev-shm]"