OSDN Git Service

adds autopilot features. samba-grid-0.2.0
authorwhitestar <whitestar@users.osdn.me>
Mon, 17 Sep 2018 10:55:42 +0000 (19:55 +0900)
committerwhitestar <whitestar@users.osdn.me>
Mon, 17 Sep 2018 10:55:42 +0000 (19:55 +0900)
cookbooks/samba-grid/CHANGELOG.md
cookbooks/samba-grid/README.md
cookbooks/samba-grid/attributes/default.rb
cookbooks/samba-grid/recipes/server.rb
cookbooks/samba-grid/templates/default/etc/cron.d/samba-local [new file with mode: 0644]
cookbooks/samba-grid/version

index 2218dd4..f42135b 100644 (file)
@@ -1,5 +1,9 @@
 # samba-grid CHANGELOG
 
+0.2.0
+-----
+- adds autopilot features.
+
 0.1.3
 -----
 - fix service control.
index 9272d59..9472c2b 100644 (file)
@@ -32,6 +32,7 @@ This cookbook sets up a Samba server.
 |:--|:--|:--|:--|
 |`['samba-grid']['group']['sambashare']['gid']`|String|`sambashare` group gid.|`nil`|
 |`['samba-grid']['group']['sambashare']['members']`|Array|`sambashare` group members|`[]`|
+|`['samba-grid']['autopilot']`|Hash|Samba services's autopilot configurations.|See `attributes/default.rb`|
 |`['samba-grid']['smb.conf']`|Hash|Samba configurations.|See `attributes/default.rb`|
 |`['samba-grid']['smb.conf']['global']`|Hash|`[global]` section configurations in the `smb.conf`.|`{}`|
 |`['samba-grid']['smb.conf']['homes']`|Hash|`[homes]` section configurations in the `smb.conf`.|`{}`|
@@ -179,7 +180,7 @@ override_attributes(
 - Author:: whitestar at osdn.jp
 
 ```text
-Copyright 2016-2017, whitestar
+Copyright 2016-2018, whitestar
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
index ce05d00..8b4e7c5 100644 (file)
@@ -2,7 +2,7 @@
 # Cookbook Name:: samba-grid
 # Attributes:: default
 #
-# Copyright 2016, whitestar
+# Copyright 2016-2018, whitestar
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -21,6 +21,11 @@ default['samba-grid']['group']['sambashare'] = {
   'gid' => nil,
   'members' => [],
 }
+default['samba-grid']['autopilot'] = {
+  'enabled' => false,
+  'log_dir' => '/var/log',
+  'wait_time' => '180s',
+}
 default['samba-grid']['smb.conf'] = {
   'global' => {
     #'workgroup' => 'WORKGROUP',
index 7a5bba7..b1ac196 100644 (file)
@@ -67,3 +67,13 @@ template '/etc/samba/smb.conf' do
   notifies :restart, 'service[samba-ad-dc]' if platform == 'debian' && platform_version < '9.0'
   #notifies :reload, 'service[samba]'
 end
+
+# autopilot
+srv = 'samba'
+template "/etc/cron.d/#{srv}-local" do
+  source  "etc/cron.d/#{srv}-local"
+  owner 'root'
+  group 'root'
+  mode '0644'
+  action :delete unless node['samba-grid']['autopilot']['enabled']
+end
diff --git a/cookbooks/samba-grid/templates/default/etc/cron.d/samba-local b/cookbooks/samba-grid/templates/default/etc/cron.d/samba-local
new file mode 100644 (file)
index 0000000..8405f58
--- /dev/null
@@ -0,0 +1,22 @@
+<%
+name = 'samba'
+
+conf = node['samba-grid']['autopilot']
+log = "#{conf['log_dir']}/#{name}-local.log"
+wait_time = conf['wait_time']
+
+cmd = nil
+st_cmd = nil
+if File.exist?('/etc/init.d/samba')
+  cmd = '/etc/init.d/samba restart'
+  st_cmd = '/etc/init.d/samba status'
+else
+  cmd = 'systemctl restart nmbd smbd'
+  st_cmd = 'systemctl status nmbd smbd'
+end
+-%>
+PATH=/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 && <%= st_cmd %> >> $LOG 2>&1