Implementing a (very) simple Maintenance mode in MDT Litetouch
While preparing for a session about MDT enhancements at the MMS 2011 (find the video at DeploymentResearch), Mikael Nyström had a very interesting idea for a web service demo. The idea was to implement something simple that allows to set a single or all locations into some kind of “Maintenance Mode”. Meaning if you have some server maintenance to do or maybe some global issues and you don’t want to have any new deployments starting, just go to a webpage and “switch off” the deployment for that particular location or even globally. So some kind of baby version of the ConfigMgr Maintenance Windows.
Having just two hours preparation allowed only a pretty simple implementation, but I think this idea has potential for further extensions as it might become handy. I especially dislike the current fact that I had to change an existing table. But more on this later.
To implement this “initial” simple version, I just added a column to the “LocationIdentity” table to store the Maintenance Information. And this “Maintenance information” is a pretty simple “YES” or “NO”. Well, as with most of those kind of configurations in MDT, anything else than a “YES” implicitly results to a “NO”.
Now all we need are four things to get it working:
- Add a new column called “Maintenance” to the LocationIdentity table of the MDT Database
- A Webpage that allows us to configure these values
- A Webservice that interprets and returns the result to the Client Computer
- A script that calls the webservice, interprets the result and stops the deployment if necessary
The Database
To add the new column to the MDT database, you can simply use the SQL Management Studio. Even the free Express version will do it (Express Editions at Microsoft).
- Open SQL Management Studio (Express)
- connect to the MDT database
- expand the MDT Database node
- expand the “Tables” node
- right click on LocationIdentity –> Design
- Create new columns with the name “Maintenance” and type of “nvarchar(50)” simply because it’s the default . Optionally set the Default Value to “NO”.
- Save your changes
The Webpage
The download on CodePlex contains a webpage that allows you to easily switch the maintenance mode for either each location individually or even globally. It has been written against .Net 4 so make sure you have it installed on your web server. It is based on the ASP.Net MVC 2 templates (see http://www.asp.net/mvc for more details about ASP.Net MVC). As it is available in source feel free to change whatever you need. There is just one thing you need to adjust to your local environment and that is to update the connection string and point it to the correct MDT database. You can do this by either using the “Connection Strings” item from the IIS Manager
or just open the web.config file from the root of this web page with your favorite XML editor.
The connection string itself seems a bit long. Just make sure you only edit the “real” connection string that you will see in the screenshots above. You can use any valid connection string format like “Data Source=SQ01;Initial Catalog=MDT2010;Integrated Security=SSPI;” to use the account of the Application pool or to connect with the credentials of a specific SQL user account as shown in the example. I personally prefer the latter. Find more information about connections strings at www.connectionstrings.com. Just make sure that the account used has read and write access to that table.
Now we can open the web page at http://YourWebServer/YourWebPage/ and it should look like this (well, with your locations)
You remember that blue background, don’t you?
The Web Service
The Web Service is now pretty easy. If you have the web page running the web service should work out of the box as it re-uses the same connection. To verify just open the page http://YourWebServer/YourWebPage/Maintenance.asmx and you should be able to see the function “GetMaintenanceStatus”.
Now you can also test the function from that page if you like. It takes just one parameter “LocationIdentifier”. In our example this is only the default Gateway. But it’s easy to use something like Active Directory sites for this (the upcoming Version 2 of the MDT Web FrontEnd adds support for using ADSites to identify the MDT location).
and we get a result as XML
The Script
In the download you will also find a script called Z_Maintenance.vbs. It has been written as a UserExit script so it’s meant to be called directly from the Gather step of MDT as this one is called as first in your Deployment process and so yields to a good point to decide if the process should continue. To get it working, just copy this script to your MDT Scripts folder and adjust your Rules file according to the sample CustomSettings.ini provided in the download as well. You actually just need to add a new section and have it called at the very beginning of your Task Sequence.
After this, make sure you update your DeploymentShare!
Now if the Gather step is called at the beginning of your deployment, it will query this Web Service function and call the UserExit script to evaluate the result. If maintenance mode is set, it will return an error to the gather step and by this stop all further processing. And just to be sure it also sets the MDT property “OSInstall” to “NO” that would also stop all MDT TaskSequences if executed anyhow.
As you can see above, the Gather step just freaks out now and no further deployments are possible. It will, however not stop already running deployments.
Final thoughts
As mentioned already, I really dislike modifying existing tables in the MDT database, as this could have side effects that I try to avoid if possible. To make something more useful out of this it should have some more possibilities:
- It should be stored in a separate table(s), that just links to the location.
- It would be nice to be able to configure Time periods to define the maintenance windows.
- Time periods should be either one-time or recurring on different periods.
- Have it link/sync/re-use existing maintenance information as available in other tools like ConfigMgr, OpsMgr, Nagios, …
- Integrate into the MDT Web FrontEnd and the Deployment Web service
- …
If you like the idea, I encourage you to share your thoughts about the design and implementation. Feel free to take the source and do whatever you want.
3 Responses
[…] binaries, just make sure you adjust the connection string to Your MDT Database (see my last post Implementing a (very) simple Maintenance Mode in MDT LiteTouch for more information on how to adjust the Connection […]
[…] to the right SQL Server/Database in the connection String of the web.config as show in the post Implementing a very simple Maintenance Mode for MDT LiteTouch). If you created something really fancy/useful with it, please share it again with the […]
[…] to the right SQL Server/Database in the connection String of the web.config as show in the post Implementing a very simple Maintenance Mode for MDT LiteTouch). If you created something really fancy/useful with it, please share it again with the […]