OSDN Git Service

adds autopilot features. platform_utils-0.7.0
authorwhitestar <whitestar@users.osdn.me>
Thu, 20 Sep 2018 13:54:52 +0000 (22:54 +0900)
committerwhitestar <whitestar@users.osdn.me>
Thu, 20 Sep 2018 13:54:52 +0000 (22:54 +0900)
cookbooks/platform_utils/CHANGELOG.md
cookbooks/platform_utils/README.md
cookbooks/platform_utils/attributes/default.rb
cookbooks/platform_utils/recipes/mount.rb [new file with mode: 0644]
cookbooks/platform_utils/recipes/networking.rb [new file with mode: 0644]
cookbooks/platform_utils/recipes/resolver.rb [new file with mode: 0644]
cookbooks/platform_utils/templates/default/etc/cron.d/mount-local [new file with mode: 0644]
cookbooks/platform_utils/templates/default/etc/cron.d/networking-local [new file with mode: 0644]
cookbooks/platform_utils/templates/default/etc/cron.d/resolved-local [new file with mode: 0644]
cookbooks/platform_utils/templates/default/usr/local/bin/mount-local [new file with mode: 0644]
cookbooks/platform_utils/version

index 914f5f2..cd9dd19 100644 (file)
@@ -1,6 +1,10 @@
 platform_utils CHANGELOG
 ========================
 
+0.7.0
+-----
+- adds autopilot features.
+
 0.6.0
 -----
 - adds the `platform_utils::rc_local` recipe. 
index 013bb66..40c4e83 100644 (file)
@@ -43,11 +43,14 @@ This cookbook provides platform utility recipes.
 |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`|
index 968a4e2..570df39 100644 (file)
 
 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'
@@ -26,6 +41,13 @@ default['platform_utils']['platform_update']['yum']['command'] = 'yum update -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
diff --git a/cookbooks/platform_utils/recipes/mount.rb b/cookbooks/platform_utils/recipes/mount.rb
new file mode 100644 (file)
index 0000000..63bb12f
--- /dev/null
@@ -0,0 +1,36 @@
+#
+# 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
diff --git a/cookbooks/platform_utils/recipes/networking.rb b/cookbooks/platform_utils/recipes/networking.rb
new file mode 100644 (file)
index 0000000..0fcc138
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# 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
diff --git a/cookbooks/platform_utils/recipes/resolver.rb b/cookbooks/platform_utils/recipes/resolver.rb
new file mode 100644 (file)
index 0000000..41e5fe1
--- /dev/null
@@ -0,0 +1,28 @@
+#
+# 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
diff --git a/cookbooks/platform_utils/templates/default/etc/cron.d/mount-local b/cookbooks/platform_utils/templates/default/etc/cron.d/mount-local
new file mode 100644 (file)
index 0000000..e3a8dfb
--- /dev/null
@@ -0,0 +1,9 @@
+<%
+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
diff --git a/cookbooks/platform_utils/templates/default/etc/cron.d/networking-local b/cookbooks/platform_utils/templates/default/etc/cron.d/networking-local
new file mode 100644 (file)
index 0000000..e824301
--- /dev/null
@@ -0,0 +1,30 @@
+<%
+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
diff --git a/cookbooks/platform_utils/templates/default/etc/cron.d/resolved-local b/cookbooks/platform_utils/templates/default/etc/cron.d/resolved-local
new file mode 100644 (file)
index 0000000..8e29e84
--- /dev/null
@@ -0,0 +1,13 @@
+<%
+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
diff --git a/cookbooks/platform_utils/templates/default/usr/local/bin/mount-local b/cookbooks/platform_utils/templates/default/usr/local/bin/mount-local
new file mode 100644 (file)
index 0000000..c269470
--- /dev/null
@@ -0,0 +1,24 @@
+#!/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