Skip to content

Commit ffeb085

Browse files
authored
Merge pull request #4 from mattlqx/reboot
look for scheduled reboot instead of pending
2 parents 6a8f202 + 100ccf3 commit ffeb085

File tree

6 files changed

+23
-7
lines changed

6 files changed

+23
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ There is some monkey-patching that needs to happen to have the option of a clean
3636
<td><tt>C:\\.kill_chef</tt> on Windows, <tt>/.kill_chef</tt> on Linux</td>
3737
</tr>
3838
<tr>
39-
<td><tt>['kill_switch']['when_reboot_pending']</tt></td>
39+
<td><tt>['kill_switch']['when_reboot_scheduled']</tt></td>
4040
<td>Bool</td>
41-
<td>Engage kill switch if there is a pending reboot</td>
41+
<td>Engage kill switch if there is a scheduled reboot (only supported on Ubuntu 16+ presently)</td>
4242
<td><tt>true</tt></td>
4343
</tr>
4444
</table>

attributes/default.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# frozen_string_literal: true
2+
13
default['kill_switch']['engage'] = false
24
default['kill_switch']['normal_exit'] = false
35
default['kill_switch']['touch_dir'] = case node['os']
46
when 'windows'
57
'C:'
68
end
79
default['kill_switch']['touch_file'] = File.join(node['kill_switch']['touch_dir'].to_s, '.kill_chef')
8-
default['kill_switch']['when_reboot_pending'] = true
10+
default['kill_switch']['when_reboot_scheduled'] = true

libraries/reboots.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
def reboot_scheduled?
4+
case node['platform']
5+
when 'ubuntu'
6+
if node['platform_version'].to_i >= 16
7+
cmd = Mixlib::ShellOut.new('busctl get-property org.freedesktop.login1 /org/freedesktop/login1 ' \
8+
'org.freedesktop.login1.Manager ScheduledShutdown')
9+
cmd.run_command
10+
return cmd.exitstatus == 0 && (cmd.stdout.include?('"poweroff"') || cmd.stdout.include?('"reboot"'))
11+
end
12+
end
13+
false
14+
end

metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
license 'MIT'
55
description 'Kill switch to prevent Chef runs from occuring'
66
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
7-
version '1.1.0'
7+
version '1.1.1'
88
chef_version '>= 12.1' if respond_to?(:chef_version)
99

1010
%w[ubuntu debian fedora centos redhat oracle scientific amazon freebsd openbsd mac_os_x solaris2 opensuse opensuseleap

recipes/default.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
reason = "node attribute ['kill_switch']['engage']"
1111
elsif File.exist?(node['kill_switch']['touch_file'])
1212
reason = "touch file #{node['kill_switch']['touch_file']}"
13-
elsif node['kill_switch']['when_reboot_pending'] && reboot_pending?
14-
reason = 'reboot pending'
13+
elsif node['kill_switch']['when_reboot_scheduled'] && reboot_scheduled?
14+
reason = 'reboot scheduled'
1515
else
1616
return
1717
end

spec/unit/recipes/default_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class FakeException < RuntimeError; end
6767
chef_run.node.normal['kill_switch']['engage'] = false
6868
allow(File).to receive(:exist?).and_call_original
6969
allow(File).to receive(:exist?).with('/.kill_chef').and_return(false)
70-
allow_any_instance_of(Chef::Recipe).to receive(:reboot_pending?).and_return(true)
70+
allow_any_instance_of(Chef::Recipe).to receive(:reboot_scheduled?).and_return(true)
7171
end
7272

7373
it 'exits noisily' do

0 commit comments

Comments
 (0)