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 "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")
61 package "hp-health" do
63 notifies :restart, "service[hp-health]"
66 service "hp-health" do
67 action [:enable, :start]
68 supports :status => true, :restart => true
71 if product.end_with?("Gen8", "Gen9")
74 notifies :restart, "service[hp-ams]"
78 action [:enable, :start]
79 supports :status => true, :restart => true
86 when "TYAN Computer Corporation"
90 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-1028U-TN10RT+", "SYS-2028U-TN24R4T+", "SYS-1029P-WTRT", "Super Server"
98 package "open-vm-tools"
100 # Remove timeSync plugin completely
101 # https://github.com/vmware/open-vm-tools/issues/302
102 file "/usr/lib/open-vm-tools/plugins/vmsvc/libtimeSync.so" do
104 notifies :restart, "service[open-vm-tools]"
107 # Attempt to tell Host we are not interested in timeSync
108 execute "vmware-toolbox-cmd-timesync-disable" do
109 command "/usr/bin/vmware-toolbox-cmd timesync disable"
113 service "open-vm-tools" do
114 action [:enable, :start]
115 supports :status => true, :restart => true
119 units.sort.uniq.each do |unit|
120 service "serial-getty@ttyS#{unit}" do
121 action [:enable, :start]
125 # if we need a different / special kernel version to make the hardware
126 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
127 # ensure that we have the package installed. the grub template will
128 # make sure that this is the default on boot.
129 if node[:hardware][:grub][:kernel]
130 kernel_version = node[:hardware][:grub][:kernel]
132 package "linux-image-#{kernel_version}-generic"
133 package "linux-image-extra-#{kernel_version}-generic"
134 package "linux-headers-#{kernel_version}-generic"
135 package "linux-tools-#{kernel_version}-generic"
137 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
138 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
139 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
144 if File.exist?("/etc/default/grub")
145 execute "update-grub" do
147 command "/usr/sbin/update-grub"
150 template "/etc/default/grub" do
155 variables :units => units, :entry => grub_entry
156 notifies :run, "execute[update-grub]"
160 execute "update-initramfs" do
162 command "update-initramfs -u -k all"
167 template "/etc/initramfs-tools/conf.d/mdadm" do
168 source "initramfs-mdadm.erb"
172 notifies :run, "execute[update-initramfs]"
177 action [:enable, :start]
180 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
184 template "/etc/default/irqbalance" do
185 source "irqbalance.erb"
191 service "irqbalance" do
192 action [:start, :enable]
193 supports :status => false, :restart => true, :reload => false
194 subscribes :restart, "template[/etc/default/irqbalance]"
197 # Link Layer Discovery Protocol Daemon
200 action [:start, :enable]
201 supports :status => true, :restart => true, :reload => true
207 if node[:virtualization][:role] != "guest" ||
208 node[:virtualization][:system] != "lxd"
210 node[:kernel][:modules].each_key do |modname|
213 tools_packages << "ssacli"
214 status_packages["cciss-vol-status"] ||= []
216 tools_packages << "ssacli"
217 status_packages["cciss-vol-status"] ||= []
219 tools_packages << "lsiutil"
220 status_packages["mpt-status"] ||= []
221 when "mpt2sas", "mpt3sas"
222 tools_packages << "sas2ircu"
223 status_packages["sas2ircu-status"] ||= []
225 tools_packages << "megactl"
226 status_packages["megaraid-status"] ||= []
228 tools_packages << "megacli"
229 status_packages["megaclisas-status"] ||= []
231 tools_packages << "arcconf"
232 status_packages["aacraid-status"] ||= []
234 tools_packages << "areca"
238 node[:block_device].each do |name, attributes|
239 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
241 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
242 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
244 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
245 status_packages["cciss-vol-status"] |= [File.basename(sg)]
251 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
252 if tools_packages.include?(tools_package)
253 package tools_package
255 package tools_package do
261 if tools_packages.include?("areca")
266 repository "https://git.openstreetmap.org/private/areca.git"
270 not_if { ENV["TEST_KITCHEN"] }
273 directory "/opt/areca" do
279 if status_packages.include?("cciss-vol-status")
280 template "/usr/local/bin/cciss-vol-statusd" do
281 source "cciss-vol-statusd.erb"
285 notifies :restart, "service[cciss-vol-statusd]"
288 systemd_service "cciss-vol-statusd" do
289 description "Check cciss_vol_status values in the background"
290 exec_start "/usr/local/bin/cciss-vol-statusd"
292 protect_system "full"
294 no_new_privileges true
295 notifies :restart, "service[cciss-vol-statusd]"
298 systemd_service "cciss-vol-statusd" do
302 template "/usr/local/bin/cciss-vol-statusd" do
307 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
308 if status_packages.include?(status_package)
309 package status_package
311 template "/etc/default/#{status_package}d" do
312 source "raid.default.erb"
316 variables :devices => status_packages[status_package]
319 service "#{status_package}d" do
320 action [:start, :enable]
321 supports :status => false, :restart => true, :reload => false
322 subscribes :restart, "template[/etc/default/#{status_package}d]"
325 package status_package do
329 file "/etc/default/#{status_package}d" do
335 disks = if node[:hardware][:disk]
336 node[:hardware][:disk][:disks]
341 # intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
343 # nvmes = if node[:hardware][:pci]
344 # node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
349 # intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
351 # if !intel_ssds.empty? || !intel_nvmes.empty?
354 # intel_ssd_tool_version = "3.0.21"
356 # remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
357 # source "https://downloadmirror.intel.com/29115/eng/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip"
360 # execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
361 # command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip isdct_#{intel_ssd_tool_version}-1_amd64.deb"
362 # cwd Chef::Config[:file_cache_path]
365 # not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb") }
368 # dpkg_package "isdct" do
369 # version "#{intel_ssd_tool_version}-1"
370 # source "#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
374 disks = disks.map do |disk|
375 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
377 if disk[:smart_device]
378 controller = node[:hardware][:disk][:controllers][disk[:controller]]
380 if controller && controller[:device]
381 device = controller[:device].sub("/dev/", "")
382 smart = disk[:smart_device]
384 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
385 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
386 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
387 elsif smart =~ /^.*,(\d+)$/
388 munin = "#{device}-#{Regexp.last_match(1)}"
389 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
390 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
393 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
394 device = Regexp.last_match(1)
397 device = disk[:device].sub("/dev/", "")
407 :hddtemp => munin.tr("-:", "_")
411 disks = disks.compact.uniq
413 if disks.count.positive?
414 package "smartmontools"
416 template "/usr/local/bin/smartd-mailer" do
417 source "smartd-mailer.erb"
423 template "/etc/smartd.conf" do
424 source "smartd.conf.erb"
428 variables :disks => disks
431 template "/etc/default/smartmontools" do
432 source "smartmontools.erb"
439 action [:enable, :start]
440 subscribes :reload, "template[/etc/smartd.conf]"
441 subscribes :restart, "template[/etc/default/smartmontools]"
444 # Don't try and do munin monitoring of disks behind
445 # an Areca controller as they only allow one thing to
446 # talk to the controller at a time and smartd will
447 # throw errors if it clashes with munin
448 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
451 munin_plugin "smart_#{disk[:munin]}" do
453 conf "munin.smart.erb"
454 conf_variables :disk => disk
459 action [:stop, :disable]
463 if disks.count.positive?
464 munin_plugin "hddtemp_smartctl" do
465 conf "munin.hddtemp.erb"
466 conf_variables :disks => disks
469 munin_plugin "hddtemp_smartctl" do
471 conf "munin.hddtemp.erb"
475 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
476 disks.map { |d| "smart_#{d[:munin]}" }
478 plugins.each do |plugin|
479 munin_plugin plugin do
481 conf "munin.smart.erb"
485 if File.exist?("/etc/mdadm/mdadm.conf")
486 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
487 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
492 file "/etc/mdadm/mdadm.conf" do
501 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
505 template "/etc/modules" do
514 subscribes :start, "template[/etc/modules]"
517 if node[:hardware][:watchdog]
520 template "/etc/default/watchdog" do
521 source "watchdog.erb"
525 variables :module => node[:hardware][:watchdog]
528 service "watchdog" do
529 action [:enable, :start]
533 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
536 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
537 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
538 chip = format("coretemp-isa-%04d", cpu)
540 temps = if File.exist?("#{coretemp}/name")
541 Dir.glob("#{coretemp}/temp*_input").map do |temp|
542 File.basename(temp).sub("temp", "").sub("_input", "").to_i
545 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
546 File.basename(temp).sub("temp", "").sub("_input", "").to_i
551 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
555 temps.each_with_index do |temp, index|
556 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
560 execute "/etc/sensors.d/chef.conf" do
562 command "/usr/bin/sensors -s"
567 template "/etc/sensors.d/chef.conf" do
568 source "sensors.conf.erb"
572 notifies :run, "execute[/etc/sensors.d/chef.conf]"
576 if node[:hardware][:shm_size]
577 execute "remount-dev-shm" do
579 command "/bin/mount -o remount /dev/shm"
588 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
589 notifies :run, "execute[remount-dev-shm]"