Web Server Change Notification or Web Server Compare or MS Deploy UI for Multi Server Sync
Introduction:
If you are interested in any of the following then you can read on:
- Getting notified in real time if any of the web servers in your web farm cluster has changed. This change can be in terms of:
- An assembly that was added to the GAC (global assembly cache)
- A registry key that was added or removed or a value added
- Some content was added, modified, deleted or some permissions on any of the content was changed
- A configuration change such as addition of a new web site or an app pool etc
- A new module that was installed or configured
- Machine config or some web configuration was modified
- A server certificate was added / deleted
- A new database was created
- Comparing any two or more servers on your cluster to see how they differ in the same terms outlined above
- Sync the changes that happened on any of the servers to one or more servers such as GAC or ACL changes
- Sync the differences between servers such as
- GAC all assemblies on server1 that are missing on server2 or more
- Copy all certificates from server1 to server2, 3, 4 … or just the delta
- Copy all Databases from server1 to server2, …
- Copy all content between servers
- Sync the entire web server1 to all others in the farm
Some snapshots:
These snapshots show 4 views of the tool. From left to right, the first one shows comparison, second one shows changes since inception on a server,third and fourth are request panes showing the requests that can be submitted to the service.
Pre-Requisites:
These are only required on the primary server that behaves as the manager. Starting RTW Web Deployment Tool has a tempAgent feature that avoids the need to install it on any box including the source.
- Microsoft SQL Server Express 2005 or 2008 [Only on the primary server that manages]
- Web Deployment Tool x86 or x64. [Only on the primary server that manages]
- MSMQ [Only on the primary server that manages. Rest the application will configure when needed or you can manually configure if you want to]
How to Use:
Step I: Install Dependencies:-
- On the source machine install:
- the database and web deployment tool.
- MSMQ by simply running ocssetup MSMQ-Server. It should be installed in a few minutes.
Step II: Copy Files:-
- Copy and unzip the files from here to any local folder of a system which you want to be the manager for the entire cluster.
- Run the CreateWSF_DB.sql.
- Run WebServerFarmManager.exe and navigate to the Administration tab on the right pane
- Here you can add the name of the servers that you need monitored.
- For each server add the username, password, domain name, db instance name on that server and whether you want db changes to be monitored.
- Set DoWatch to true. Any server that has this value as false, will not be monitored.
- For any server if the user, that service will run as, has admin rights to all servers then you can leave the username and password fields blank.
- On this pane you can also change the default values in the app.config based on your needs.
- Change the db connection string
- Change the bin path to the location you copied the binary files to
- Here you can also install / uninstall the webserverfarmwatch service and start and stop the service. So go ahead and install and start the service if you have already added the databases.
Step III: Using the application
- The WebServerFarm Watch svc takes a snapshot of the all the servers in the farm that you listed on the servers page.
- Run webserverfarmmanager. One cool thing now is that it has a log messages pane that shows all the progress from all the servers in the UI. So if you happen to have connection issues or any other problems you should see that being logged in this pane. You don't need to look into any other logs.
- In the left pane the top pane shows the changes that have happened as of now or any of the servers. Click on any server listed in the tree view to see any changes. Mind you this IS LIVE. If you go onto any server and add an assembly to the gac or add a registry key under the ones its monitoring or add / change / modify any content or set or remove ACL this view should show you immediately. The only changes that are not live and need to be requested are the configuration changes, certificate addition and db creation. But these you can easily get just by double-clicking on any of the servers in the list. It will immediately retrieve and show you all the changes including the configuration change.
- The lower left pane shows the server comparison report. Since you have not compared yet it will be empty.
- On the right pane navigate to the “Submit Requests” tab.
- From the action drop down choose “Compare Servers”. From the list boxes below chose any one source server and choose any or all of the destination servers and submit request.
- Wait for a few minutes to process and double-click the left lower pane node or close and re-start the app. You will see a list of server comparison nodes.
- Click on any of the nodes under the server comparison node in the lower left pane and you will see a comparison report of all.
- The name of the tabs are self explanatory. The tabs are:
- Content: Content changes from inception or difference in content on source and destination.
- For changes view it shows all the files that have changed in any regard or added or deleted.
- For comparison it shows only the content folders that are missing on source or destination
- Registry Key:
- Changes view: Any or all changes to registry since inception. The list of registry monitored is in the regkeyManifest.xml. You can change / add / remove more keys to monitored as per your needs and restart the service. If you change this file on this parent server manager it will affect all the servers but if you change this file on any given server then the change is local
- Comparison View: It does not compare or sync registry changes. This is because the changes to the registry are evil and I do not want to automate it.
- Gac:
- Changes View: Any file that was added to / removed from the GAC
- Comparison View: All assemblies that are missing on the source or destination in the GAC. It says ONLY_ON_SOURCE or ONLY_ON_DEST in the message column.
- Certificates
- Changes View: Any server certificate that was added to / removed from the MY store
- Comparison View: All server certificates that are missing on the source or destination in the MY store. It says ONLY_ON_SOURCE or ONLY_ON_DEST in the message column.
- MS SQL DB
- Changes View: Any database that was created since inception
- Comparison View: All databases that are missing on the source or destination. It says ONLY_ON_SOURCE or ONLY_ON_DEST in the message column.
- AppHostConfig or App Pool Config or Machine Config or Root Web Config
- Changes View: Any configuration changes since inception.
- Comparison View: All changes that would actually happen if you performed a sync.
- Content: Content changes from inception or difference in content on source and destination.
- Functions:
- Get Changes on server: This ,as explained above, is mostly live and the rest can be retrieved by double-clicking any server in the upper part of the left pane which shows servers list
- Compare any two servers: This was again explained above in Step III item 4
- Sync Changes: This should be useful. It lets you carry over any change that happened on one server to 1 or more servers.
- You can selectively propagate a type of change to any of the servers you care.
- For e.g. if 2 assemblies were added to the gac and a database was added on Server1 while 10 files were uploaded on server2.
- Navigate to the submit requests pane and choose “Sync Changes” from the action drop down
- Choose the GAC and DB from the changetype list.
- Choose Server1 and any number of destination servers. It does not let you choose multiple source because these syncs are run parallel in multiple threads and not sequentially.
- Submit request
- Then choose Server2 as source and choose content as the changetype and re-submit request. The requests sequentially submitted are processed sequentially while the multiple requests within a request are processed simultaneously.
- You should see the destination changes appear in the changes view
- Sync Servers:
- This lets you sync all the differences between any two or more servers.
- For e.g. I have 3 servers. S1, S2 and S3.
- S1 has 10 more assemblies gac’ed , 3 more databases and 5 extra certificates, 3 new sites, 2 new app pools than S2 and 20 more assemblies gac’ed but same number of databases and 2 fewer certificates and some apppool changes and some site differences as compared to S3.
- Choose Sync Servers from the drop down and choose GAC, DB, Cert, Content, Apphostconfig, apppoolconfig from the changetype list
- Choose S1 as the source and S2 and S3 as the destinations.
- Submit request. All of the above differences will be synced except for the 2 certificates that are missing in S1.
- Resubmit request with S3 as source and S1 as destination and change type as cert. This will sync all 3 servers.
- Accept Changes:
- As the name suggests, this is there to clear the db and cache of all the change lists once you are done dealing with them.
How it works:
A basic representation of how it works
The service: [WebServerFarmWatcher Svc]
- Creates two local queues if they don’t exist with the names MSDeployRequestQueue and MSDeployResponseQueue
- Enumerates all the servers and for each server:
- Calls the getsnapshot function of SyncManager class
- Instantiates an object of WebServerWatcher class
- It then starts listening for messges on the two queues mentioned above
- Any request received on MSDeployRequestQueue is processed and Queues a seperate thread to process every command within a request. Such as if a sync request is received from Server1 to Server2, Server3, Server4, it will queue 3 threads to serve this request
- Any response received on MSDeployResponseQueue is added to the DB
The WebServerWatcher class:
- It enumerates all content folders and starts listening for any and all changes to the content.
- Copies the remote notification svc on the server and starts it
- Sends a message to get an initial snapshot of GAC, Databases and certificates
- Any change notification it receives for content is added to the database
The SyncManager class:
- This is just a wrapper for MSDeploy API
- It implements the basic sync, compare and getchanges functions along with the trace listeners.
The RemNotificationSvc:
- On start it gets all the keys specified in regkeymanifest.xml and starts waiting on change notification for these regkeys
- It processes requests from the WebServerWatcher for getting a GAC , DB and certificate snapshot or for changes in DB and certificate. It also resolves any assembly that is GAC’ed and provides its complete name
The WebServerFarmManager UI:
- All it does is display the data in the UI based on which node the data is being requested on and
- Submit request to the service based on the users needs.
- It does not listen to any MSMQ queue except the log queue.
The only ones that listen to the Queues are the parent service class on the server manager, the UI (log queue) and the remnotificationsvc on each of the servers being monitored.
Code:
You can download the entire code with the solution file from here
Acknowledgements and tool re-use:
- Madhur Joshi for taking his time to provide valuable feedback
- Web Deployment Tool which is the core of all the synchronization that this does.
- Junfeng Zhang for the GACWrapper that I used after some trimming of the stuff that I did not need.