diff --git a/cookbooks/fb_init_sample/metadata.rb b/cookbooks/fb_init_sample/metadata.rb index 4a95b82d..8a683ee1 100644 --- a/cookbooks/fb_init_sample/metadata.rb +++ b/cookbooks/fb_init_sample/metadata.rb @@ -57,6 +57,7 @@ 'fb_screen', 'fb_sdparm', 'fb_securetty', + 'fb_smartmon', 'fb_storage', 'fb_stunnel', 'fb_sudo', diff --git a/cookbooks/fb_init_sample/recipes/default.rb b/cookbooks/fb_init_sample/recipes/default.rb index d844ebf8..ac1943b6 100644 --- a/cookbooks/fb_init_sample/recipes/default.rb +++ b/cookbooks/fb_init_sample/recipes/default.rb @@ -119,6 +119,7 @@ end include_recipe 'fb_motd' include_recipe 'fb_profile' +include_recipe 'fb_smartmon' if node.firstboot_tier? include_recipe 'fb_init_sample::firstboot' diff --git a/cookbooks/fb_smartmon/README.md b/cookbooks/fb_smartmon/README.md new file mode 100644 index 00000000..4026598e --- /dev/null +++ b/cookbooks/fb_smartmon/README.md @@ -0,0 +1,29 @@ +fb_smartmon Cookbook +==================== +This cookbook manages the package `smartmontools` and `smartctl` +as well as the server `smartd` + +Requirements +------------ + +Attributes +---------- +* node['fb_smartmon']['enable'] +* node['fb_smartmon']['config'][$DIRECTIVE][$CONFIG] + +Usage +----- +By default this cookbook will install the `smartmontools` package +which allows the `smartctl` command to be used. + +By default `node['fb_smartmon']['enable']` is set to false which +disables the `smartd` service + +Setting `node['fb_smartmon']['enable']` to `true` will enable the +`smartd` service + +`node['fb_smartmon']['config'][$DIRECTIVE][$CONFIG]` controls +the `/etc/smartd.conf` config. The `$DIRECTIVE` can be a device +device such as `/dev/sda` - or a command such as `DEVICESCAN` +or `DEFAULT`. `$CONFIG` can be used to specify an options the +directive takes (see smartd.conf man pages). diff --git a/cookbooks/fb_smartmon/attributes/default.rb b/cookbooks/fb_smartmon/attributes/default.rb new file mode 100644 index 00000000..783bd44c --- /dev/null +++ b/cookbooks/fb_smartmon/attributes/default.rb @@ -0,0 +1,34 @@ +# vim: syntax=ruby:expandtab:shiftwidth=2:softtabstop=2:tabstop=2 +# +# Copyright (c) 2022-present, Vicarious, Inc. +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +return unless node.linux? + +if node['block_device'].keys.any? { |x| x.start_with?('nvme') } + devicetype = 'nvme' +else + devicetype = 'auto' +end + +default['fb_smartmon'] = { + 'enable' => false, + 'config' => { + 'devicescan' => { + '-d' => devicetype, + }, + }, +} diff --git a/cookbooks/fb_smartmon/metadata.rb b/cookbooks/fb_smartmon/metadata.rb new file mode 100644 index 00000000..3cda4075 --- /dev/null +++ b/cookbooks/fb_smartmon/metadata.rb @@ -0,0 +1,11 @@ +# Copyright (c) 2022-present, Viarious, Inc. +name 'fb_smartmon' +maintainer 'Facebook' +maintainer_email 'noreply@facebook.com' +license 'All Rights Reserved' +source_url 'https://github.com/facebook/chef-cookbooks/' +description 'Installs/Configures fb_smartmon' +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +# never EVER change this number, ever. +version '0.1.0' +depends 'fb_helpers' diff --git a/cookbooks/fb_smartmon/recipes/default.rb b/cookbooks/fb_smartmon/recipes/default.rb new file mode 100644 index 00000000..3b61532b --- /dev/null +++ b/cookbooks/fb_smartmon/recipes/default.rb @@ -0,0 +1,40 @@ +# +# Cookbook:: fb_smartmon +# Recipe:: default +# +# Copyright (c) 2016-present, Facebook, Inc. +# All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +package 'smartmontools' do + action :upgrade +end + +template '/etc/smartd.conf' do + owner 'root' + group 'root' + mode '0644' +end + +service 'smartd' do + only_if { node['fb_smartmon']['enable'] } + action [:enable, :start] +end + +service 'disable smartd' do + service_name 'smartd' + not_if { node['fb_smartmon']['enable'] } + action [:stop, :disable] +end diff --git a/cookbooks/fb_smartmon/templates/smartd.conf.erb b/cookbooks/fb_smartmon/templates/smartd.conf.erb new file mode 100644 index 00000000..2208cff7 --- /dev/null +++ b/cookbooks/fb_smartmon/templates/smartd.conf.erb @@ -0,0 +1,5 @@ +# This file is controlled by Chef, do not modify! +<% node.default['fb_smartmon']['config'].each do |section, config| %> +<%= section.upcase %> <%= config.to_a.flatten.join(' ') %> + +<% end %>