Created
September 20, 2011 19:14
-
-
Save stevendanna/1230032 to your computer and use it in GitHub Desktop.
Example of extending Package::Apt to prohibit service start-up. Warning: Unreliable.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Chef::Provider::Package::Apt | |
def install_package(name, version) | |
package_name = "#{name}=#{version}" | |
package_name = name if @is_virtual_package | |
run_command_with_systems_locale(:command => "printf '#!/bin/sh\n\exit 101' > /usr/sbin/policy-rc.d && chmod +x /usr/sbin/policy-rc.d") if @new_resource.prohibit_start | |
begin | |
run_command_with_systems_locale(:command => "apt-get -q -y#{expand_options(@new_resource.options)} install #{package_name}", | |
:environment => { | |
"DEBIAN_FRONTEND" => "noninteractive" | |
} | |
) | |
ensure | |
run_command_with_systems_locale(:command => "rm /usr/sbin/policy-rc.d") if @new_resource.prohibit_start | |
end | |
end | |
end | |
class Chef::Resource::Package | |
def initialize(name, run_context=nil) | |
super | |
@resource_name = :package | |
@package_name = name | |
@version = nil | |
@candidate_version = nil | |
@response_file = nil | |
@source = nil | |
@action = :install | |
@options = nil | |
@prohibit_start = false | |
@allowed_actions.push(:install, :upgrade, :remove, :purge) | |
end | |
def prohibit_start(arg=nil) | |
set_or_return(:prohibit_start, | |
arg, | |
:kind_of => [TrueClass, FalseClass]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment