Draining IIS before stopping services

Razzi29 331 Reputation points
2024-04-26T14:11:55.5+00:00

Is there a best practice or clean procedure to drain IIS server from current sessions before stopping the services for the purpose of maintenance?

Internet Information Services
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,555 questions
{count} votes

Accepted answer
  1. MotoX80 34,431 Reputation points
    2024-04-29T13:46:36.6133333+00:00

    Copy an app_offline page to the root to tell users that maintenance begins in 5 minutes. Then recycle the worker processes.

    https://stackoverflow.com/questions/1153449/asp-net-2-0-how-to-use-app-offline-htm

    Powershell script to start with. Adjust as needed.

    copy-item C:\YourWebStuff\app_offline.htm  -Destination C:\Inetpub\wwwroot\ 
    start-sleep -Seconds (60 * 5)                   # give users 5 minutes to see the message    
    (Get-IISAppPool -Name DefaultAppPool).stop()    # use your pool name
    start-sleep -Seconds 30                         # give it some time
    get-process w3wp | stop-process -force          # kill IIS wp if it won't stop
    
    # do maintenance here 
    
    remove-item C:\Inetpub\wwwroot\app_offline.htm      # tell IIS to serve up the site 
    (Get-IISAppPool -Name DefaultAppPool).start()       # restart the app pool  
    
    
    

    If app_offline doesn't work for you, then define 2 sites with the same network bindings. One site is your main app site, the second site is just simple htm pages that show a message that the site is down for maintenance. That second site is stopped by default. When you want to do maintenance, stop the first site and start the second. When maint is complete, stop the second and start the first.


1 additional answer

Sort by: Most helpful
  1. Razzi29 331 Reputation points
    2024-04-29T12:49:17.2266667+00:00

    @Yurong Dai-MSFT Appreciate the response, but not quire what I was looking for as I am aware of performing those checks; I was looking more of an automated PowerShell script process or thrid party tool that can provide me a very fast/ quick way of just draining local IIS services on a particular system.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.