Skip to content

Commit

Permalink
Merge pull request #233 from criteo-forks/iis_native_module
Browse files Browse the repository at this point in the history
[GH-232] Adds IIS native module install/uninstall
  • Loading branch information
EasyAsABC123 committed Dec 8, 2015
2 parents a4c5db4 + 9e14409 commit 1b07b17
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,13 +504,17 @@ Manages modules globally or on a per site basis.

- `:add` - add a new module
- `:delete` - delete a module
- `:install` - install a native module from the filesystem (.dll)
- `:delete` - uninstall a native module

### Attribute Parameters

- `module_name` - The name of the module to add or delete
- `type` - The type of module
- `precondition` - precondition for module
- `application` - The application or site to add the module to
- `add` - Whether the module you install has to be globally added
- `image` - Location of the DLL of the module to install

### Example

Expand Down
2 changes: 1 addition & 1 deletion libraries/matcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def config_iis_config(command)
)
end

[:add, :delete].each do |action|
[:add, :delete, :install, :uninstall].each do |action|
self.class.send(:define_method, "#{action}_iis_module", proc do |module_name|
ChefSpec::Matchers::ResourceMatcher.new(:iis_module, action, module_name)
end
Expand Down
34 changes: 34 additions & 0 deletions providers/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,40 @@ def whyrun_supported?
end
end

# appcmd syntax for installing native modules
# appcmd install module /name:string /add:string(true|false) /image:string
action :install do
if !@current_resource.exists
converge_by("install IIS module #{new_resource.module_name}") do
cmd = "#{appcmd(node)} install module /name:\"#{new_resource.module_name}\""
cmd << " /add:\"#{new_resource.add}\"" unless new_resource.add.nil?
cmd << " /image:\"#{new_resource.image}\"" if new_resource.image

shell_out!(cmd, returns: [0, 42])

Chef::Log.info("#{new_resource} installed module '#{new_resource.module_name}'")
end
else
Chef::Log.debug("#{new_resource} module already exists - nothing to do")
end
end

# appcmd syntax for uninstalling native modules
# appcmd uninstall module <name>
action :uninstall do
if @current_resource.exists
converge_by("uninstall IIS module #{new_resource.module_name}") do
cmd = "#{appcmd(node)} uninstall module \"#{new_resource.module_name}\""

shell_out!(cmd, returns: [0, 42])
end

Chef::Log.info("#{new_resource} uninstalled module '#{new_resource.module_name}'")
else
Chef::Log.debug("#{new_resource} module does not exists - nothing to do")
end
end

def load_current_resource
@current_resource = Chef::Resource::IisModule.new(new_resource.name)
@current_resource.module_name(new_resource.module_name)
Expand Down
4 changes: 3 additions & 1 deletion resources/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
# limitations under the License.
#

actions :add, :delete
actions :add, :delete, :install, :uninstall
default_action :add

attribute :module_name, kind_of: String, name_attribute: true
attribute :type, kind_of: String, default: nil
attribute :add, kind_of: [FalseClass, TrueClass], default: nil
attribute :image, kind_of: String, default: nil
attribute :precondition, kind_of: String, default: nil
attribute :application, kind_of: String, default: nil

Expand Down

0 comments on commit 1b07b17

Please sign in to comment.