diff options
| author | Max Martin <max@puppetlabs.com> | 2011-03-22 16:54:53 -0700 |
|---|---|---|
| committer | Max Martin <max@puppetlabs.com> | 2011-03-30 12:56:56 -0700 |
| commit | f5aabf52631afbda92dca1b5a90a3198bc4baf99 (patch) | |
| tree | d61352766a2dca5a6794a2bfae4fa07ba4331c87 | |
| parent | 5693e41291593cd69888fdb0536f616c4f5e3d10 (diff) | |
| download | puppet-f5aabf52631afbda92dca1b5a90a3198bc4baf99.tar.gz puppet-f5aabf52631afbda92dca1b5a90a3198bc4baf99.tar.xz puppet-f5aabf52631afbda92dca1b5a90a3198bc4baf99.zip | |
(#5908) Add support for new update-rc.d disable API
Added support for the new disable API to update-rc.d and
added spec tests to check this functionality. This change was made
because in versions of sysv-rc >= 2.88, 'update-rc.d stop' is broken and
actually enables the service.
We only changed the disable case as the enable case still works on
systems which use sysv-rc 2.88 or greater (atm, only Debian Lenny). We
wanted to change as little as possible because update-rc.d prints a
message stating that the new enable/disable API is unstable and may
change in the future.
Paired-with:Matt Robinson, Jacob Helwig
| -rwxr-xr-x | lib/puppet/provider/service/debian.rb | 8 | ||||
| -rwxr-xr-x | spec/unit/provider/service/debian_spec.rb | 16 |
2 files changed, 20 insertions, 4 deletions
diff --git a/lib/puppet/provider/service/debian.rb b/lib/puppet/provider/service/debian.rb index 3d09e2849..58b808a8e 100755 --- a/lib/puppet/provider/service/debian.rb +++ b/lib/puppet/provider/service/debian.rb @@ -22,8 +22,12 @@ Puppet::Type.type(:service).provide :debian, :parent => :init do # Remove the symlinks def disable - update_rc "-f", @resource[:name], "remove" - update_rc @resource[:name], "stop", "00", "1", "2", "3", "4", "5", "6", "." + if `dpkg --compare-versions $(dpkg-query -W --showformat '${Version}' sysv-rc) ge 2.88 ; echo $?`.to_i == 0 + update_rc @resource[:name], "disable" + else + update_rc "-f", @resource[:name], "remove" + update_rc @resource[:name], "stop", "00", "1", "2", "3", "4", "5", "6", "." + end end def enabled? diff --git a/spec/unit/provider/service/debian_spec.rb b/spec/unit/provider/service/debian_spec.rb index 8dee2ee94..440d4491b 100755 --- a/spec/unit/provider/service/debian_spec.rb +++ b/spec/unit/provider/service/debian_spec.rb @@ -52,8 +52,20 @@ describe provider_class do end describe "when disabling" do - it "should call update-rc.d twice" do - @provider.expects(:update_rc).twice + it "should be able to disable services with newer sysv-rc versions" do + @provider.stubs(:`).with("dpkg --compare-versions $(dpkg-query -W --showformat '${Version}' sysv-rc) ge 2.88 ; echo $?").returns "0" + + @provider.expects(:update_rc).with(@resource[:name], "disable") + + @provider.disable + end + + it "should be able to enable services with older sysv-rc versions" do + @provider.stubs(:`).with("dpkg --compare-versions $(dpkg-query -W --showformat '${Version}' sysv-rc) ge 2.88 ; echo $?").returns "1" + + @provider.expects(:update_rc).with("-f", @resource[:name], "remove") + @provider.expects(:update_rc).with(@resource[:name], "stop", "00", "1", "2", "3", "4", "5", "6", ".") + @provider.disable end end |
