platform_utils CHANGELOG
========================
+0.7.0
+-----
+- adds autopilot features.
+
0.6.0
-----
- adds the `platform_utils::rc_local` recipe.
|Key|Type|Description, example|Default|
|:--|:--|:--|:--|
|`['platform_utils']['kernel_modules']['loaded_modules']`|Array|Loaded extra kernel module names.|`[]`|
+|`['platform_utils']['mount']['autopilot']`|Hash|mount autopilot configurations.|See `attributes/default.rb`|
+|`['platform_utils']['networking']['autopilot']`|Hash|networking autopilot configurations.|See `attributes/default.rb`|
|`['platform_utils']['platform_update']['auto_update']`|Boolean|whether update automatically or not.|`true`|
|`['platform_utils']['platform_update']['timer']`|Symbol|update execution timing.|`:delayed`|
|`['platform_utils']['platform_update']['apt-get']['command']`|String|apt-get upgrade/dist-upgrade command string.|`'apt-get upgrade -y'`|
|`['platform_utils']['platform_update']['yum']['command']`|String|yum update command string.|`'yum update -y'`|
|`['platform_utils']['rc_local']`|Array|`/etc/rc.local` lines.|`[]`|
+|`['platform_utils']['resolver']['autopilot']`|Hash|systemd-resolved autopilot configurations.|See `attributes/default.rb`|
|`['platform_utils']['subid']['users']`|Array|Subordinate user (=group) names.|`[]`|
|`['platform_utils']['subid']['notifies']`|Array, Hash|Notifies by the subordinate user/group file update.|`[]`, See `attributes/default.rb`|
|`['platform_utils']['sudo']['sudoers.d']`|Hash|sudoers file configurations.|`{}` See `attributes/default.rb`|
default['platform_utils']['kernel_modules']['loaded_modules'] = []
+default['platform_utils']['mount']['autopilot'] = {
+ # for delayed hotplug devices (e.g. usb)
+ 'enabled' => false,
+ 'log_dir' => '/var/log',
+ 'wait_time' => '60s',
+ 'mount_points' => [],
+}
+default['platform_utils']['networking']['autopilot'] = {
+ # for delayed unstable networking
+ 'enabled' => false,
+ 'log_dir' => '/var/log',
+ 'wait_time' => '60s',
+ 'init_type' => nil, # 'init', 'systemd', 'netplan'
+}
+
default['platform_utils']['platform_update']['auto_update'] = true
default['platform_utils']['platform_update']['timer'] = :delayed
default['platform_utils']['platform_update']['apt-get']['command'] = 'apt-get upgrade -y'
default['platform_utils']['rc_local'] = []
+default['platform_utils']['resolved']['autopilot'] = {
+ # for local dns server used by the systemd-resolved
+ 'enabled' => false,
+ 'log_dir' => '/var/log',
+ 'wait_time' => '120s',
+}
+
default['platform_utils']['subid']['users'] = []
default['platform_utils']['subid']['notifies'] = [
=begin
--- /dev/null
+#
+# Cookbook Name:: platform_utils
+# Recipe:: mount
+#
+# Copyright 2018, whitestar
+#
+# 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.
+#
+
+# autopilot
+srv = 'mount'
+template "/etc/cron.d/#{srv}-local" do
+ source "etc/cron.d/#{srv}-local"
+ owner 'root'
+ group 'root'
+ mode '0644'
+ action :delete unless node['platform_utils']['mount']['autopilot']['enabled']
+end
+
+template "/usr/local/bin/#{srv}-local" do
+ source "usr/local/bin/#{srv}-local"
+ owner 'root'
+ group 'root'
+ mode '0755'
+ action :delete unless node['platform_utils']['mount']['autopilot']['enabled']
+end
--- /dev/null
+#
+# Cookbook Name:: platform_utils
+# Recipe:: networking
+#
+# Copyright 2018, whitestar
+#
+# 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.
+#
+
+# autopilot
+srv = 'networking'
+template "/etc/cron.d/#{srv}-local" do
+ source "etc/cron.d/#{srv}-local"
+ owner 'root'
+ group 'root'
+ mode '0644'
+ action :delete unless node['platform_utils']['networking']['autopilot']['enabled']
+end
--- /dev/null
+#
+# Cookbook Name:: platform_utils
+# Recipe:: resolver
+#
+# Copyright 2018, whitestar
+#
+# 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.
+#
+
+# autopilot
+srv = 'resolved'
+template "/etc/cron.d/#{srv}-local" do
+ source "etc/cron.d/#{srv}-local"
+ owner 'root'
+ group 'root'
+ mode '0644'
+ action :delete unless node['platform_utils']['resolver']['autopilot']['enabled']
+end
--- /dev/null
+<%
+name = 'mount'
+
+conf = node['platform_utils']['mount']['autopilot']
+wait_time = conf['wait_time']
+-%>
+PATH=/usr/bin:/bin:/usr/local/bin
+
+@reboot root sleep <%= wait_time %> && mount-local
--- /dev/null
+<%
+name = 'networking'
+
+conf = node['platform_utils']['networking']['autopilot']
+log = "#{conf['log_dir']}/#{name}-local.log"
+wait_time = conf['wait_time']
+
+cmd = nil
+if File.exist?('/etc/init.d/networking')
+ cmd = '/etc/init.d/networking restart'
+else
+ cmd = 'systemctl restart systemd-networkd'
+end
+
+unless conf['init_type'].nil?
+ case conf['init_type']
+ when 'init'
+ cmd = '/etc/init.d/networking restart'
+ when 'systemd'
+ cmd = 'systemctl restart systemd-networkd'
+ when 'netplan'
+ cmd = 'netplan apply'
+ end
+end
+-%>
+PATH=/usr/sbin:/usr/bin:/bin:/usr/local/bin
+DATE_F='+%Y-%m-%d %H:%M:%S %z'
+LOG=<%= log %>
+
+@reboot root sleep <%= wait_time %> && date "$DATE_F" > $LOG && <%= cmd %> >> $LOG 2>&1 && sleep 10s && ip addr show scope global >> $LOG 2>&1
--- /dev/null
+<%
+name = 'resolved'
+
+conf = node['platform_utils']['resolver']['autopilot']
+log = "#{conf['log_dir']}/#{name}-local.log"
+wait_time = conf['wait_time']
+-%>
+PATH=/usr/bin:/bin:/usr/local/bin
+DATE_F='+%Y-%m-%d %H:%M:%S %z'
+LOG=<%= log %>
+NAME=systemd-resolved
+
+@reboot root sleep <%= wait_time %> && date "$DATE_F" > $LOG && systemctl restart $NAME >> $LOG 2>&1 && systemctl status $NAME >> $LOG 2>&1
--- /dev/null
+#!/bin/sh
+<%
+name = 'mount'
+
+conf = node['platform_utils']['mount']['autopilot']
+log = "#{conf['log_dir']}/#{name}-local.log"
+
+mount_points = conf['mount_points']
+-%>
+PATH=/usr/bin:/bin:/usr/local/bin
+DATE_F='+%Y-%m-%d %H:%M:%S %z'
+LOG=<%= log %>
+mount_points='<%= mount_points.join(' ') %>'
+
+date "$DATE_F" > $LOG
+for m in $mount_points; do
+ if mount | grep -sq $m; then
+ echo "$m is already mounted." >> $LOG
+ else
+ echo "$m is not mounted yet." >> $LOG
+ echo "mount $m ..." >> $LOG
+ mount -v $m >> $LOG 2>&1
+ fi
+done