How to Recycle Application Pool on Remote Server


 

I work with several customers that release highly anticipated information on the web sites on specific days of the month and anticipation of the load, some of the customers recycle the application pool for the application to start out with a minimal memory footprint.

In order to recycle the application pools, the customers were logging into each server and opening the IIS Manager console (run –> intemgr), selecting the application pool, and recycling. This is a tedious exercise when there are 20+ servers in the farm.

We implemented the following command as the customers utilizes Web Deploy for application and web deployments and the following script can be run from a single workstation to remotely recycle the application pool using the sync verb and the –source is recycleApp:

msdeploy.exe -verb:sync -source:recycleApp -dest:recycleApp="WebSite1/Application",computername=10.0.0.15

In a sync operation, specify recycleApp for both the source and dest arguments and in the dest argument, specify the application path and any provider settings. If the target server is remote, include the computername parameter in the dest argument.

A batch file can be created with the IP address of each server as a line in the file. Or, a PowerShell script could be created to loop a list of servers and send the command to each server in the list.

Please note, the Web Deployment service must be running on the remote server and the logged in user must be a member of the administrator group. Instructions on how to allow a non-administrator to recycle the application pools are listed in this blog post: http://blogs.msdn.com/b/asiatech/archive/2011/07/21/iis-7-delegate-remote-application-pool-recycling-for-non-administrator.aspx

Local Server:

There are two options when logged onto the server with the first being the appcmd utility:

appcmd list app /site.name:"WebSite1/Application" /xml | appcmd list apppool /in /xml | appcmd recycle apppool /in

and the second option is the Web Deploy utility

msdeploy.exe -verb:sync -source:recycleApp="WebSite1/Application" -dest:recycleApp="WebSite1/Application"

More detail on the recycleApp provider is found here http://technet.microsoft.com/en-us/library/ee522997(v=WS.10).aspx

Use the appcmd list wp command to verify the application pool has recycled before and after the recycle to see the PID changing. Or, update the settings in the application pool to log the manual recycle action in the System Event log file.

Comments (4)

  1. Andy S says:

    I couldn't get the syntax shown above to work for a remote recycle situation, I kept getting a Provider Not Found (ERROR_PROVIDER_NOT_FOUND) error.  I also came across the same syntax on MS/TechNet (technet.microsoft.com/…/ee522997(v=ws.10).aspx).  I noticed that the TechNet page contradicts the stated syntax when it mentions that the "sync" verb should have the recycleApp specified for both source AND destination, and when I added that it worked:

    "C:Program Files (x86)IISMicrosoft Web Deploy V3msdeploy.exe" -verb:sync -source:recycleApp -dest:recycleApp="MySite/OptionalApplicationName",computername=10.0.0.15

    Thanks for the article, hopefully this helps others as well.

  2. Eric Parvin says:

    Andy S, you are absolutely correct in the syntax and I have updated the blog posting to reflect this information. Thanks again!

  3. Manuel Rebello de Andrade says:

    Alternative method using PowerShell (must be run using elevated privilege)

    $appcmd=”C:\Windows\System32\inetsrv\appcmd.exe”

    $servers = @( “«server1»”, “«server2»” )

    # Use the following command to determine attributes other than path which you can use to filter upon:
    #
    # C:\Windows\System32\inetsrv\appcmd.exe list apps /xml
    $sitepath=”/«yoursitepath»”
    $filter=”/path:””” + $sitepath + “”””

    $script = $appcmd + ” list apps ” + $filter + ” /xml | ” + $appcmd + ” list apppool /in /xml | ” + $appcmd + ” recycle apppool /in”

    ForEach( $server in $servers )
    {
    “Recycling ” + $server

    Try
    {
    Invoke-Command -ComputerName $server -ScriptBlock { $script }
    }
    Catch
    {
    # Uncomment the line below if you want to add the names of unavailable computers to a text file
    # Add-Content Unavailable-Computers.txt $server
    }
    }

    1. Eric Parvin says:

      This is a fantastic method to automate the process and I will need to test in out in my lab. Thanks for sharing!

Skip to main content