Share via


Deploy an Application to a Web Farm/Synchronize All Computers in a Web Farm

This sample demonstrates how to write a command-line script to perform the following tasks in the web farm scenario:

  1. Deploy an application from a developer provided package onto multiple machines in a web farm.

    Deploying a new application package or upgrading an application to a newer version across multiple machines can be a tedious task. A script that sends the package and perform the deployment on the remote machines will simplify this task.

  2. Synchronize both the content and the configuration on all computers in a web farm to a single model computer.

    Applying multiple changes to a Web farm requires that all changes be applied to all computers in exactly the same way. If all of the changes that are needed are scripted, this is an easy task. Otherwise it presents the problem of how to record and reproduce all the changes on all computers in the Web farm. Another solution is to apply all the changes to a single computer and then replicate it across the Web farm.

This sample shows how to use the Web Deployment Tool (MSDeploy) to deploy an application package, or to replicate the content and configuration of a single server to all the computers in the Web farm. This sample will work with any MSDeploy application packages. We recommend the Common AppFabric Sample Application, which was created for use with Microsoft AppFabric 1.1 for Windows Server samples. To find this application package, navigate to the <samples>\ Samples\Management\MultiMachineSyncAndDeploy \Code\CalculatorService.zip file, where <samples> is the path under which you have installed the AppFabric samples. The script can be easily modified to meet specific needs, for example, to rename the deployed application or to synchronize only a single site.

Note

Samples are provided for educational purposes only. They are not intended to be used in a production environment and have not been tested in a production environment. Microsoft does not provide technical support for these samples.

Prerequisites

This sample needs two or more computers that meet the following requirements:

  1. The Web Deployment Tool’s Remote Agent Service (also called Deployment Agent Service) must be installed and running on all computers. By default AppFabric installs the Web Deployment Tool, but its Remote Agent Service is not part of the default installation. To add the Remote Agent Service to your installation:

    1. Open the Programs and Features Control Panel, select Web Deployment Tool, and then click Change.

    2. When prompted, click Next, and on the following screen click Change.

    3. After the list of features is displayed, make sure that Remote Agent Service is marked Will be installed on the local hard drive, and then complete the setup wizard.

    4. After the wizard completes, start the service by typing net start msdepsvc in a command window. If you want the service to be automatically started every time Windows starts, type sc config msdepsvc start=auto in a command window.

    To learn more about the installation and configuration of the Web Deployment Tool, or to install it on a computer that doesn’t have AppFabric installed, refer to https://learn.iis.net/page.aspx/421/installing-the-web-deployment-tool/.

  2. All computers that will be modified during the synchronization must allow the World Wide Web Services (HTTP) through their firewall.

  3. All computers of the Web farm must be part of a domain, and the account that you use to synchronize the farm must have administrative privileges on all computers.

If using a custom provider, it may be useful at times to determine if it is recognized by the Remote Agent Service. There are two methods for determining what providers are available.

  1. Using IIS - From within IIS Manager right-click on an application, select Deploy, and then select Export Application. In the Export Application dialog box, click Manage Components. Within the Providers column click on the last empty line, and then click on the down-arrow. This shows the list of available providers including any custom providers that are recognized by the Remote Agent Service.

  2. Using the command line – Enter MSDEPLOY.EXE in a command prompt on the Web Deploy Tool command line. Part of the information displayed will be the available custom providers. For information on how to install the Web Deploy Tool, refer to Refer to Install the Web Deployment Tool.

It is possible to modify the sample script to run in a non-domain environment. To read more about the authentication options of the Web Deploy Tool, see the authType option on https://technet.microsoft.com/en-us/library/dd569001(WS.10).aspx.

Sample Location and Files

All files that you will need to run this sample are located in <samples>\Samples\Management\MultiMachineSyncAndDeploy\Code:

  • machines.txt

  • sync.cmd

  • syncOne.cmd

  • deployOne.cmd

Setting Up and Running This Sample

Task1: Deploy a package.

  1. Copy all the files from <samples>\Samples\Management\SyncConfigFromModelMachine\Code to the administrative computer.

  2. Edit the machines.txt file to contain the names of all other computers in the farm that you want to modify in a single batch. You need to place one computer name per line.

  3. Run the sync.cmd -fromPackage <package file path> command.

  4. Inspect the log files for errors. Each computer will have its own log file named sync-MACHINE.log where the MACHINE portion is replaced with the name of that computer.

Task2: Sync to a model machine.

  1. After all the computers in your farm meet the preceding requirements, you can start by making the application or site configuration changes to one of those computers. We will refer to that computer as the “model computer.”

  2. After the configuration is done, copy all the files from <samples>\Samples\Management\SyncConfigFromModelMachine\Code to the model computer.

  3. Edit the machines.txt file to contain the names of all other computers in the farm that you want to modify in a single batch. You need to place one computer name per line.

  4. Run the sync.cmd -fromLocalServer command and enter Y to confirm.

  5. Inspect the log files for errors. Each computer will have its own log file named sync-MACHINE.log where the MACHINE portion is replaced with the name of that computer.

Understanding This Sample

The sync.cmd script first validates the command-line arguments the user provides:

if "%1"=="" goto print_syntax
if "%1"=="-fromLocalServer" goto sync_server
if "%1"=="-fromPackage" goto sync_package
goto print_syntax

Depending on the argument, the script calls the deployOne.cmd or syncOne.cmd script once for each computer specified in the machines.txt. It does this by using the for command and the start command to invoke the subsequent script so that the task will be performed simultaneously on the target machines.

for /f %%i in ('type machines.txt') do (start deployOne.cmd %%i %2 %3 )

Or

for /f %%i in ('type machines.txt') do ( start syncOne.cmd %%i %1) 

SyncOne.cmd/DeployOne.cmd is a script that uses the command-line interface of Web Deploy, a command called msdeploy.exe, to synchronize a remote IIS web server with the package or the entire IIS web server on the local machine.

msdeploy.exe -verb:sync -source:package=%2 -dest:auto,computername=%1 %3

Or

msdeploy.exe -verb:sync -source:webServer -dest:webServer,computername=%1 %2

The first parameter is the computer name passed from sync.cmd and the package file path is required by the deployOne.cmd script as the second parameter. The last and optional parameter is any parameter that you want to pass to the msdeploy. This is useful if you want to pass an additional parameter to Web Deploy without needing to modify any of the scripts. One such additional parameter might be -whatif:

sync.cmd -whatif

When Web Deploy executes with the -whatif parameter it checks for all errors that might occur during the execution of the specified command without actually executing that command. We recommend that you execute the sync command in a production environment with -whatif to see if any errors can occur. Taking this precautionary step can prevent ending in an inconsistent state.

Removing This Sample

To remove this sample, delete all its files from the admin/model computer.

Other Resources

For more information about the Web Deployment Tool, see https://learn.iis.net/page.aspx/346/web-deployment-tool/.

For more information about how to use Web Deploy to synchronize two servers running IIS 7.0, see https://learn.iis.net/page.aspx/446/synchronize-iis-70/.

To learn more about the installation and configuration of the Web Deployment Tool, see https://learn.iis.net/page.aspx/421/installing-the-web-deployment-tool/.

  2012-09-12