Archive for January, 2012

The New Hype: Top Shelf Project for building Windows Services

January 30, 2012 Leave a comment

Lately my coder compadres have been all a flutter about something called Top-Shelf-Project, an open source project for building windows services for .NET or Mono platforms.

What’s so great about it? I don’t know. I’m trying to find out.  I’ll be back in an hour…

Okay, it’s been more than an hour, but I had to go refill my iced espresso and space out for a minute or two.

Here’s what I’ve found out:

The Top Shelf project allows you to deploy behavior in a similar fashion to a traditional Windows Service, but without the need to create an actual Windows Service project type – a Console Application will suffice, and without all the scaffolding that a regular Windows Service project requires.  You can just run a short bit of fluent configuration in your Console App’s Main routine to configure a regular .NET type as a service. You then have the option to debug it as a Console App (which is a bit easier than having to install and then attach to a traditional Windows Service).

So that’s three nice things there:

  1. less scaffolding,
  2. easier debugging options
  3. fluent style configuration.

That’s a good start.

There’s a few more reasons to dig it besides. Top Shelf bakes some additional goodness into its fluent Host Configuration – namely some convenient command line installation parameters.  Its sort of like magic. I had to check out the source code to see how they did this just to convince myself that it would really work.  Its baked into the host configuration routine.  It looks for command line arguments like “Install” and then handles the nitty gritty of actually installing your console app as a service.

So you build your console app and then just run it from the command line with the “install” argument.

like: c:\boogersugarservice.exe install

The traditional way of installing a Windows Service these days is really not so bad. I wrote a powershell script to uninstall, copy and reinstall a windows service recently – using installutil.  No biggie.  This doesn’t change that scenario all that much, but at least its self-contained and you don’t even need to get a separate utility involved.  Any time even a single step can be eliminated from a deployment procedure my brain releases some happiness chemicals.

Then there’s this whole SHELVING concept.  First of all, what’s up with this metaphor?  I’ve gotten used to using this term in the context of TFS source control and spent a few minutes fumbling about trying to disambiguate that from the meaning in this context.

I could be wrong here, but best guess is you can deploy and startup a new service as easily as throwing a book on a shelf – something like that? Maybe? No?  Well whatever.

Basically shelving involves the use of a TopShelf Service Host. The intention of the host is to allow you to deploy and re-deploy services and have them auto-magically stop/uninstall/reinstall/start in a similar fashion to when you modify the web.config file of a site in IIS and IIS auto-magically knows to recycle the app pool and reload the config.

I haven’t tried this out yet. I’ve been perusing the discussion forums and seeing a fair amount of trouble with production implementations of this.  Makes me a little nervous. But I’ll have to try it out for myself and see.  I will report the results in a future post.

Categories: Uncategorized