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"
146 template "/etc/default/grub" do
151 variables :units => units, :entry => grub_entry
152 notifies :run, "execute[update-grub]"
156 execute "update-initramfs" do
158 command "update-initramfs -u -k all"
163 template "/etc/initramfs-tools/conf.d/mdadm" do
164 source "initramfs-mdadm.erb"
168 notifies :run, "execute[update-initramfs]"
173 action [:enable, :start]
176 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
180 service "irqbalance" do
181 action [:start, :enable]
182 supports :status => false, :restart => true, :reload => false
185 # Link Layer Discovery Protocol Daemon
188 action [:start, :enable]
189 supports :status => true, :restart => true, :reload => true
195 if node[:virtualization][:role] != "guest" ||
196 (node[:virtualization][:system] != "lxc" &&
197 node[:virtualization][:system] != "lxd" &&
198 node[:virtualization][:system] != "openvz")
200 node[:kernel][:modules].each_key do |modname|
203 tools_packages << "ssacli"
204 status_packages["cciss-vol-status"] ||= []
206 tools_packages << "ssacli"
207 status_packages["cciss-vol-status"] ||= []
209 tools_packages << "lsiutil"
210 status_packages["mpt-status"] ||= []
211 when "mpt2sas", "mpt3sas"
212 tools_packages << "sas2ircu"
213 status_packages["sas2ircu-status"] ||= []
215 tools_packages << "megactl"
216 status_packages["megaraid-status"] ||= []
218 tools_packages << "megacli"
219 status_packages["megaclisas-status"] ||= []
221 tools_packages << "arcconf"
222 status_packages["aacraid-status"] ||= []
224 tools_packages << "areca"
228 node[:block_device].each do |name, attributes|
229 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
231 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
232 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
234 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
235 status_packages["cciss-vol-status"] |= [File.basename(sg)]
241 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
242 if tools_packages.include?(tools_package)
243 package tools_package
245 package tools_package do
251 if tools_packages.include?("areca")
256 repository "https://git.openstreetmap.org/private/areca.git"
260 not_if { ENV["TEST_KITCHEN"] }
263 directory "/opt/areca" do
269 if status_packages.include?("cciss-vol-status")
270 template "/usr/local/bin/cciss-vol-statusd" do
271 source "cciss-vol-statusd.erb"
275 notifies :restart, "service[cciss-vol-statusd]"
278 systemd_service "cciss-vol-statusd" do
279 description "Check cciss_vol_status values in the background"
280 exec_start "/usr/local/bin/cciss-vol-statusd"
282 protect_system "full"
284 no_new_privileges true
285 notifies :restart, "service[cciss-vol-statusd]"
288 systemd_service "cciss-vol-statusd" do
292 template "/usr/local/bin/cciss-vol-statusd" do
297 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
298 if status_packages.include?(status_package)
299 package status_package
301 template "/etc/default/#{status_package}d" do
302 source "raid.default.erb"
306 variables :devices => status_packages[status_package]
309 service "#{status_package}d" do
310 action [:start, :enable]
311 supports :status => false, :restart => true, :reload => false
312 subscribes :restart, "template[/etc/default/#{status_package}d]"
315 package status_package do
319 file "/etc/default/#{status_package}d" do
325 disks = if node[:hardware][:disk]
326 node[:hardware][:disk][:disks]
331 intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
333 nvmes = if node[:hardware][:pci]
334 node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
339 intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
341 if !intel_ssds.empty? || !intel_nvmes.empty?
344 intel_ssd_tool_version = "3.0.25"
346 remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
347 source "https://downloadmirror.intel.com/29556/eng/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip"
350 execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
351 command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
352 cwd Chef::Config[:file_cache_path]
355 not_if { ::File.exist?("#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux/isdct_#{intel_ssd_tool_version}-1_amd64.deb") }
358 dpkg_package "isdct" do
359 version "#{intel_ssd_tool_version}-1"
360 source "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
364 disks = disks.map do |disk|
365 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
367 if disk[:smart_device]
368 controller = node[:hardware][:disk][:controllers][disk[:controller]]
370 if controller && controller[:device]
371 device = controller[:device].sub("/dev/", "")
372 smart = disk[:smart_device]
374 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
375 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
376 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
377 elsif smart =~ /^.*,(\d+)$/
378 munin = "#{device}-#{Regexp.last_match(1)}"
379 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
380 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
383 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
384 device = Regexp.last_match(1)
387 device = disk[:device].sub("/dev/", "")
397 :hddtemp => munin.tr("-:", "_")
401 disks = disks.compact.uniq
403 if disks.count.positive?
404 package "smartmontools"
406 template "/etc/cron.daily/update-smart-drivedb" do
407 source "update-smart-drivedb.erb"
413 template "/usr/local/bin/smartd-mailer" do
414 source "smartd-mailer.erb"
420 template "/etc/smartd.conf" do
421 source "smartd.conf.erb"
425 variables :disks => disks
428 template "/etc/default/smartmontools" do
429 source "smartmontools.erb"
435 service "smartmontools" do
436 action [:enable, :start]
437 subscribes :reload, "template[/etc/smartd.conf]"
438 subscribes :restart, "template[/etc/default/smartmontools]"
441 # Don't try and do munin monitoring of disks behind
442 # an Areca controller as they only allow one thing to
443 # talk to the controller at a time and smartd will
444 # throw errors if it clashes with munin
445 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
448 munin_plugin "smart_#{disk[:munin]}" do
450 conf "munin.smart.erb"
451 conf_variables :disk => disk
455 template "/etc/prometheus/collectors/smart.devices" do
456 source "smart.devices.erb"
460 variables :disks => disks
463 prometheus_collector "smart" do
468 action [:stop, :disable]
472 if disks.count.positive?
473 munin_plugin "hddtemp_smartctl" do
474 conf "munin.hddtemp.erb"
475 conf_variables :disks => disks
478 munin_plugin "hddtemp_smartctl" do
480 conf "munin.hddtemp.erb"
484 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
485 disks.map { |d| "smart_#{d[:munin]}" }
487 plugins.each do |plugin|
488 munin_plugin plugin do
490 conf "munin.smart.erb"
494 if File.exist?("/etc/mdadm/mdadm.conf")
495 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
496 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
501 file "/etc/mdadm/mdadm.conf" do
510 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
514 template "/etc/modules" do
523 subscribes :start, "template[/etc/modules]"
526 if node[:hardware][:watchdog]
529 template "/etc/default/watchdog" do
530 source "watchdog.erb"
534 variables :module => node[:hardware][:watchdog]
537 service "watchdog" do
538 action [:enable, :start]
542 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
545 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
546 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
547 chip = format("coretemp-isa-%04d", cpu)
549 temps = if File.exist?("#{coretemp}/name")
550 Dir.glob("#{coretemp}/temp*_input").map do |temp|
551 File.basename(temp).sub("temp", "").sub("_input", "").to_i
554 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
555 File.basename(temp).sub("temp", "").sub("_input", "").to_i
560 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
564 temps.each_with_index do |temp, index|
565 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
569 execute "/etc/sensors.d/chef.conf" do
571 command "/usr/bin/sensors -s"
576 template "/etc/sensors.d/chef.conf" do
577 source "sensors.conf.erb"
581 notifies :run, "execute[/etc/sensors.d/chef.conf]"
585 if node[:hardware][:shm_size]
586 execute "remount-dev-shm" do
588 command "/bin/mount -o remount /dev/shm"
597 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
598 notifies :run, "execute[remount-dev-shm]"