Disclaimer: This is my first ruby experiment ever. It should work fine on a box with IIS7+, but if for some reason it doesn’t, please create an issue. And of course, any feedback is welcome.
inetmgr is a Ruby library that helps automate the configuration of IIS 7.0 or higher. It provides a ruby-like (e.g. no clumsy Properties.Item, CreateNewElement, AddElement goo) API on top of the standard IIS configuration API, which lets you (transactionally) inspect add/remove and modify various IIS objects like sites, application pools, bindings, virtual directories, etc.
Additionally, intemgr provides some basic rake tasks (still working on this) that help adding IIS deployment aspects to your build (& deploy) process.
How to install?
Get the gem:
> gem install inetmgr
Or clone the repo:
> git clone git@github.com:typesafe/inetmgr.git inetmgr
Why?
Let an example speak for itself… Here how you add a site with some standard defaults in C# (the vbscript and javascript variants are very alike):
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
ConfigurationElement siteElement = sitesCollection.CreateElement("site");
siteElement["name"] = @"Contoso";
siteElement["id"] = 2;
siteElement["serverAutoStart"] = true;
ConfigurationElementCollection bindingsCollection = siteElement.GetCollection("bindings");
ConfigurationElement bindingElement = bindingsCollection.CreateElement("binding");
bindingElement["protocol"] = @"http";
bindingElement["bindingInformation"] = @"*:80:www.contoso.com";
bindingsCollection.Add(bindingElement);
ConfigurationElementCollection siteCollection = siteElement.GetCollection();
ConfigurationElement applicationElement = siteCollection.CreateElement("application");
applicationElement["path"] = @"/";
ConfigurationElementCollection applicationCollection = applicationElement.GetCollection();
ConfigurationElement virtualDirectoryElement = applicationCollection.CreateElement("virtualDirectory");
virtualDirectoryElement["path"] = @"/";
virtualDirectoryElement["physicalPath"] = @"C:\Inetpub\www.contoso.com\wwwroot";
applicationCollection.Add(virtualDirectoryElement);
siteCollection.Add(applicationElement);
sitesCollection.Add(siteElement);
serverManager.CommitChanges();
}
}
}
And here’s how you do it with inetmgr in Ruby:
require 'inetmgr'
IisConfiguration.configure do |cfg|
cfg.get_sites.add do |site|
site.name = "Contoso"
site.auto_start = true
site.bindings.add do |b|
b.protocol = "http"
b.binding_information = "*:80:www.contoso.com"
end
site.applications.add do |app|
app.path = "/"
app.virtual_directories.add do |dir|
dir.path = "/"
dir.physical_path = "C:\\Inetpub\\www.contoso.com\\wwwroot"
end
end
end
end
I don’t know about you, but I know which version I choose.
License
Copyright © 2010 Gino Heyman
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
One Trackback/Pingback
[...] .Net thoughts by Gino Heyman AboutAbout inetmgr « Solving the Trailing Slash Problem in ASP.Net MVC using a [...]