Monday, September 29, 2014

The 10 commandments of software development

A couple of weeks ago fellow senior Bastiaan de Rijber and I were venting some frustration on Skype. We realized that we find ourselves repeating the same tidbits of wisdom over and over again to developers in conversations, code reviews and post mortems on failures, big and and small.

I’ll admit the title seems a bit ‘holier-than-thou’ so I’m going to stick to the theme and do this all biblical style:

  1. Thou shall not assume, for assumptions are the mother of all fuckups
  2. Thou shall not blame the tooling, for it's probably thou who has made the mistake
  3. Thou shall clean up thy shit, for there is no greater pleasure than deleting code
  4. Thou shall not optimize prematurely, for premature optimization is the root of all evil
  5. Thou must find the root cause before applying the 'fix'
  6. Thou shall not practice the black art of multi threading without Jedi assistance
  7. Thou shall not commit shortly before going home/on vacation/to sleep
  8. Thou shall review thy code before committing
  9. Thou shall not proclaim the obvious in comments
  10. Thou shall not claim 'It works on my machine'

Of course we have a bunch more of these…

Thursday, May 15, 2014

Migrating sites from IIS7 to IIS8

I was recently tasked with migrating a bunch of sites from a Windows 2008 server to a Windows 2012 server. I expected this to be a well know path but it’s not. I tried to use WebDeploy, it’s a complete disaster.
I ended up cherry-picking IIS configuration backups in a merge tool. Not pretty but it worked like a charm.
What’s wrong with WebDeploy
WebDeploy is mostly an automation tool for deploying websites. It assumes a bunch of things. For example that you already created the site and the apppool. I am not looking to do that by hand 20 times or so.
It also seems to be incapable of creating virtual directories etc. In effect, a deployment package for a site seems to contain only files, none of the IIS structural configuration that’s so tedious to setup by hand.
Looking for ways to migrate the IIS configuration itself I found that WebDeploy supports server level packages too. This seems to create a package with all sites and a whole slew of configuration data. Great, or so I thought.
When I tried to deploy that on the server I found that IIS would no longer work. At all.
WebDeploy had messed up the .NET Framework configuration files, machine wide!
The alternative
I was not looking forward to manually configuring 15 sites with their app pools, virtual directories and all that. The chances of me messing that up in multiple places are 100%.
So I started looking into IIS’ built-in backup functionality:
%windir%\system32\inetsrv\appcmd add backup "migration" 
This creates a backup of the IIS configuration in
%windir%\system32\inetsrv\backup\migration
The backup consists of XML files and being a developer, I know how to deal with XML.
Next step is to create a backup on the destination server. I named that ‘Pre-Migration’ and copied it to ‘Migration’ so I would have a version to return to i
The file that has the actual site configurations is applicationHost.config, and is mostly compatible between IIS7 and IIS8. The XML is pretty straight forward and I was able to merge the bits I wanted into the backup file on the new server.
The relevant sections are:
  • applicationPools
  • sites
  • locations
Now restore the backup:
%windir%\system32\inetsrv\appcmd restore backup "migration"