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.
20 include_recipe "tools"
21 include_recipe "munin"
23 ohai_plugin "hardware" do
24 template "ohai.rb.erb"
27 case node[:cpu][:"0"][:vendor_id]
29 package "intel-microcode"
31 package "amd64-microcode"
34 if node[:dmi] && node[:dmi][:system]
35 case node[:dmi][:system][:manufacturer]
37 manufacturer = node[:dmi][:base_board][:manufacturer]
38 product = node[:dmi][:base_board][:product_name]
40 manufacturer = node[:dmi][:system][:manufacturer]
41 product = node[:dmi][:system][:product_name]
44 manufacturer = "Unknown"
50 if node[:roles].include?("bytemark") || node[:roles].include?("exonetric")
58 package "hp-health" do
60 notifies :restart, "service[hp-health]"
63 service "hp-health" do
64 action [:enable, :start]
65 supports :status => true, :restart => true
68 if product.end_with?("Gen8", "Gen9")
71 notifies :restart, "service[hp-ams]"
75 action [:enable, :start]
76 supports :status => true, :restart => true
83 when "TYAN Computer Corporation"
87 when "H8DGU", "X9SCD", "X7DBU", "X7DW3", "X9DR7/E-(J)LN4F", "X9DR3-F", "X9DRW", "SYS-1028U-TN10RT+", "SYS-2028U-TN24R4T+", "SYS-1029P-WTRT", "Super Server"
95 package "open-vm-tools"
97 service "open-vm-tools" do
98 action [:enable, :start]
99 supports :status => true, :restart => true
103 units.sort.uniq.each do |unit|
104 service "serial-getty@ttyS#{unit}" do
105 action [:enable, :start]
109 # if we need a different / special kernel version to make the hardware
110 # work (e.g: https://github.com/openstreetmap/operations/issues/45) then
111 # ensure that we have the package installed. the grub template will
112 # make sure that this is the default on boot.
113 if node[:hardware][:grub][:kernel]
114 kernel_version = node[:hardware][:grub][:kernel]
116 package "linux-image-#{kernel_version}-generic"
117 package "linux-image-extra-#{kernel_version}-generic"
118 package "linux-headers-#{kernel_version}-generic"
119 package "linux-tools-#{kernel_version}-generic"
121 boot_device = IO.popen(["df", "/boot"]).readlines.last.split.first
122 boot_uuid = IO.popen(["blkid", "-o", "value", "-s", "UUID", boot_device]).readlines.first.chomp
123 grub_entry = "gnulinux-advanced-#{boot_uuid}>gnulinux-#{kernel_version}-advanced-#{boot_uuid}"
128 if File.exist?("/etc/default/grub")
129 execute "update-grub" do
131 command "/usr/sbin/update-grub"
134 template "/etc/default/grub" do
139 variables :units => units, :entry => grub_entry
140 notifies :run, "execute[update-grub]"
144 execute "update-initramfs" do
146 command "update-initramfs -u -k all"
151 template "/etc/initramfs-tools/conf.d/mdadm" do
152 source "initramfs-mdadm.erb"
156 notifies :run, "execute[update-initramfs]"
161 action [:enable, :start]
164 package "ipmitool" if node[:kernel][:modules].include?("ipmi_si")
168 template "/etc/default/irqbalance" do
169 source "irqbalance.erb"
175 service "irqbalance" do
176 action [:start, :enable]
177 supports :status => false, :restart => true, :reload => false
178 subscribes :restart, "template[/etc/default/irqbalance]"
181 # Link Layer Discovery Protocol Daemon
184 action [:start, :enable]
185 supports :status => true, :restart => true, :reload => true
191 node[:kernel][:modules].each_key do |modname|
194 tools_packages << "ssacli"
195 status_packages["cciss-vol-status"] ||= []
197 tools_packages << "ssacli"
198 status_packages["cciss-vol-status"] ||= []
200 tools_packages << "lsiutil"
201 status_packages["mpt-status"] ||= []
202 when "mpt2sas", "mpt3sas"
203 tools_packages << "sas2ircu"
204 status_packages["sas2ircu-status"] ||= []
206 tools_packages << "megactl"
207 status_packages["megaraid-status"] ||= []
209 tools_packages << "megacli"
210 status_packages["megaclisas-status"] ||= []
212 tools_packages << "arcconf"
213 status_packages["aacraid-status"] ||= []
215 tools_packages << "areca"
219 node[:block_device].each do |name, attributes|
220 next unless attributes[:vendor] == "HP" && attributes[:model] == "LOGICAL VOLUME"
222 if name =~ /^cciss!(c[0-9]+)d[0-9]+$/
223 status_packages["cciss-vol-status"] |= ["cciss/#{Regexp.last_match[1]}d0"]
225 Dir.glob("/sys/block/#{name}/device/scsi_generic/*").each do |sg|
226 status_packages["cciss-vol-status"] |= [File.basename(sg)]
231 %w[ssacli lsiutil sas2ircu megactl megacli arcconf].each do |tools_package|
232 if tools_packages.include?(tools_package)
233 package tools_package
235 package tools_package do
241 if tools_packages.include?("areca")
246 repository "https://git.openstreetmap.org/private/areca.git"
251 directory "/opt/areca" do
257 if status_packages.include?("cciss-vol-status")
258 template "/usr/local/bin/cciss-vol-statusd" do
259 source "cciss-vol-statusd.erb"
263 notifies :restart, "service[cciss-vol-statusd]"
266 systemd_service "cciss-vol-statusd" do
267 description "Check cciss_vol_status values in the background"
268 exec_start "/usr/local/bin/cciss-vol-statusd"
270 protect_system "full"
272 no_new_privileges true
273 notifies :restart, "service[cciss-vol-statusd]"
277 %w[cciss-vol-status mpt-status sas2ircu-status megaraid-status megaclisas-status aacraid-status].each do |status_package|
278 if status_packages.include?(status_package)
279 package status_package
281 template "/etc/default/#{status_package}d" do
282 source "raid.default.erb"
286 variables :devices => status_packages[status_package]
289 service "#{status_package}d" do
290 action [:start, :enable]
291 supports :status => false, :restart => true, :reload => false
292 subscribes :restart, "template[/etc/default/#{status_package}d]"
295 package status_package do
299 file "/etc/default/#{status_package}d" do
305 disks = if node[:hardware][:disk]
306 node[:hardware][:disk][:disks]
311 # intel_ssds = disks.select { |d| d[:vendor] == "INTEL" && d[:model] =~ /^SSD/ }
313 # nvmes = if node[:hardware][:pci]
314 # node[:hardware][:pci].values.select { |pci| pci[:driver] == "nvme" }
319 # intel_nvmes = nvmes.select { |pci| pci[:vendor_name] == "Intel Corporation" }
321 # if !intel_ssds.empty? || !intel_nvmes.empty?
324 # intel_ssd_tool_version = "3.0.21"
326 # remote_file "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
327 # source "https://downloadmirror.intel.com/29115/eng/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip"
330 # execute "#{Chef::Config[:file_cache_path]}/Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip" do
331 # command "unzip Intel_SSD_Data_Center_Tool_#{intel_ssd_tool_version}_Linux.zip isdct_#{intel_ssd_tool_version}-1_amd64.deb"
332 # cwd Chef::Config[:file_cache_path]
335 # not_if { File.exist?("#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb") }
338 # dpkg_package "isdct" do
339 # version "#{intel_ssd_tool_version}-1"
340 # source "#{Chef::Config[:file_cache_path]}/isdct_#{intel_ssd_tool_version}-1_amd64.deb"
344 disks = disks.map do |disk|
345 next if disk[:state] == "spun_down" || %w[unconfigured failed].any?(disk[:status])
347 if disk[:smart_device]
348 controller = node[:hardware][:disk][:controllers][disk[:controller]]
350 if controller && controller[:device]
351 device = controller[:device].sub("/dev/", "")
352 smart = disk[:smart_device]
354 if device.start_with?("cciss/") && smart =~ /^cciss,(\d+)$/
355 array = node[:hardware][:disk][:arrays][disk[:arrays].first]
356 munin = "cciss-3#{array[:wwn]}-#{Regexp.last_match(1)}"
357 elsif smart =~ /^.*,(\d+)$/
358 munin = "#{device}-#{Regexp.last_match(1)}"
359 elsif smart =~ %r{^.*,(\d+)/(\d+)$}
360 munin = "#{device}-#{Regexp.last_match(1)}:#{Regexp.last_match(2)}"
363 elsif disk[:device] =~ %r{^/dev/(nvme\d+)n\d+$}
364 device = Regexp.last_match(1)
367 device = disk[:device].sub("/dev/", "")
377 :hddtemp => munin.tr("-:", "_")
381 disks = disks.compact.uniq
383 if disks.count.positive?
384 package "smartmontools"
386 template "/usr/local/bin/smartd-mailer" do
387 source "smartd-mailer.erb"
393 template "/etc/smartd.conf" do
394 source "smartd.conf.erb"
398 variables :disks => disks
401 template "/etc/default/smartmontools" do
402 source "smartmontools.erb"
409 action [:enable, :start]
410 subscribes :reload, "template[/etc/smartd.conf]"
411 subscribes :restart, "template[/etc/default/smartmontools]"
414 # Don't try and do munin monitoring of disks behind
415 # an Areca controller as they only allow one thing to
416 # talk to the controller at a time and smartd will
417 # throw errors if it clashes with munin
418 disks = disks.reject { |disk| disk[:smart]&.start_with?("areca,") }
421 munin_plugin "smart_#{disk[:munin]}" do
423 conf "munin.smart.erb"
424 conf_variables :disk => disk
429 action [:stop, :disable]
433 if disks.count.positive?
434 munin_plugin "hddtemp_smartctl" do
435 conf "munin.hddtemp.erb"
436 conf_variables :disks => disks
439 munin_plugin "hddtemp_smartctl" do
441 conf "munin.hddtemp.erb"
445 plugins = Dir.glob("/etc/munin/plugins/smart_*").map { |p| File.basename(p) } -
446 disks.map { |d| "smart_#{d[:munin]}" }
448 plugins.each do |plugin|
449 munin_plugin plugin do
451 conf "munin.smart.erb"
455 if File.exist?("/etc/mdadm/mdadm.conf")
456 mdadm_conf = edit_file "/etc/mdadm/mdadm.conf" do |line|
457 line.gsub!(/^MAILADDR .*$/, "MAILADDR admins@openstreetmap.org")
462 file "/etc/mdadm/mdadm.conf" do
471 subscribes :restart, "file[/etc/mdadm/mdadm.conf]"
475 template "/etc/modules" do
484 subscribes :start, "template[/etc/modules]"
487 if node[:hardware][:watchdog]
490 template "/etc/default/watchdog" do
491 source "watchdog.erb"
495 variables :module => node[:hardware][:watchdog]
498 service "watchdog" do
499 action [:enable, :start]
503 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
506 Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
507 cpu = File.basename(coretemp).sub("coretemp.", "").to_i
508 chip = format("coretemp-isa-%04d", cpu)
510 temps = if File.exist?("#{coretemp}/name")
511 Dir.glob("#{coretemp}/temp*_input").map do |temp|
512 File.basename(temp).sub("temp", "").sub("_input", "").to_i
515 Dir.glob("#{coretemp}/hwmon/hwmon*/temp*_input").map do |temp|
516 File.basename(temp).sub("temp", "").sub("_input", "").to_i
521 node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
525 temps.each_with_index do |temp, index|
526 node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
530 execute "/etc/sensors.d/chef.conf" do
532 command "/usr/bin/sensors -s"
537 template "/etc/sensors.d/chef.conf" do
538 source "sensors.conf.erb"
542 notifies :run, "execute[/etc/sensors.d/chef.conf]"
546 if node[:hardware][:shm_size]
547 execute "remount-dev-shm" do
549 command "/bin/mount -o remount /dev/shm"
558 options "rw,nosuid,nodev,size=#{node[:hardware][:shm_size]}"
559 notifies :run, "execute[remount-dev-shm]"