Caution when stopping and starting an IIS application pool with appcmd

When starting and stopping IIS 7 application pools from command line with appcmd.exe, you should be aware of a behavior that can sometimes lead to unintended circumstances.

To explain it, lets first review what happens when you stop an application pool with the InetMgr.exe tool:

1) Set the autoStart property of the <applicationPool> configuration element to false.  This causes WAS to not start any worker processes when a new request to an application mapped to the application pool arrives.

2) Call IIS RSCA (runtime status and control API) to stop the application pool, which instructs all w3wp.exe processes in that application pool to shut down (gracefully at first, then killed if they exceed the shutdownTimeLimit).  WAS will remember that the apppool is stopped while it is loaded, and any subsequent requests to the apppool will return a 503.

These are two logical actions - #2 being a transient action to terminate the apppool's current processes, and #1 being a persistent directive not to start the apppool.

Now, lets say you use appcmd in your script to start or stop the application pool, e.g.:

%windir%\system32\inetsrv\appcmd stop apppool "DefaultAppPool"

...

%windir%\system32\inetsrv\appcmd start apppool "DefaultAppPool"

The difference is, AppCmd will only perform #2 - use RSCA to tell the application pool to start or stop.  Because AppCmd does not set the autoStart config property, when you restart WAS (e.g. reboot or do an IISRESET) - the application pool state will be reset and it will be eligible for starting automatically based on the current autoStart setting.

This could mean, that you stopped the application pool, IISRESET, and all of a sudden your application is live again taking load balancer traffic.  If you were debugging/deploying this application in production, this could be bad!

While you may consider this a bug, the argument I had with the software test engineer back in the day was that while InetMgr has to err on the side of convinience and safety, AppCmd should err on the side of flexibility and degree of control, and split these actions. I am not so sure anymore in this case, but at this point it is what it is. 

So, if you are using appcmd, be sure to do:

%windir%\system32\inetsrv\appcmd stop apppool "DefaultAppPool"

%windir%\system32\inetsrv\appcmd set apppool "DefaultAppPool" /autoStart:false

OR

%windir%\system32\inetsrv\appcmd start apppool "DefaultAppPool"

%windir%\system32\inetsrv\appcmd set apppool "DefaultAppPool" /autoStart:true

Of course, since these actions are separate, you have flexibility to decide whether you want to perform the start/stop as a persistent action or just temporary until the next WAS reset.

Regards,

Mike

Published 12 May 10 12:24 by Mike Volodarsky
Filed under: , ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# MVolo's Blog said on May 12, 2010 1:18 AM:

When starting and stopping IIS 7 application pools from command line with appcmd.exe, you should be aware

# MVolo's Blog said on May 12, 2010 2:11 AM:

When starting and stopping IIS 7 application pools from command line with appcmd.exe, you should be aware

# Daniel said on May 25, 2010 12:52 AM:
I don't suppose there's a similar command line for IIS 6.0?
# Crispin said on October 19, 2010 12:28 PM:
Shouldn't you be ordering the first appcmd's the other way round, lest it tries to autostart before you actually tell it that autostart is, now, false? Or is there sufficient delay that it won't? i.e. %windir%\system32\inetsrv\appcmd set apppool "DefaultAppPool" /autoStart:false %windir%\system32\inetsrv\appcmd stop apppool "DefaultAppPool"
# said on December 21, 2010 12:44 AM:

tnx

# said on March 21, 2011 1:13 PM:
i think there something wrong with the iss 7.0 in the defaultapppool
# said on March 31, 2011 9:31 PM:

For every company/person that relies on Skype numbers this should be a big concern your numbers might just vanish and skype "support" will not "support" you to get them back at all.

This is a long story toked about 16 hours with skype so called chat support .. actually I could call them time wasters since no support provided but loosing time .

All facts in this story can be proved with chats history with skype so called support.

In a few words we were preparing a voip server based on asterisk using 6 phone numbers and 10 channels from skype "business manager" for our customer.

The server was supposed to be inbound server for an radio advertising campaign that had funds of 15000 usd for first day .

Everything was working ok till 10 hours before first advertising. About this time a colleague noticed that numbers were not connecting anymore.

I've tested with an other skype business manager account and the numbers from that account were connecting ok while the original ones were not.

We've contacted skype support mentioning the importance of having the numbers back working as soon as possible and they could not offer any

answer just mentioning an locked account .. reason of ???!!!???? .. not known .. the account was owned by a US company that bought 6 phone numbers,

10 channels and credited the account with about 100 usd for calls ..

Since we had the time pressure on us for getting the numbers back online we've tried to move them from one business account to other one ...

but guess what .. !!!! by this move the original account that hold 6 phone numbers,10 voip channels and about 100 dollars vanished .. !!!!!

It just got vanished .. !!!! skype ???? after all this we have spent over 16 hours with the "helpful" (or rather not helpful) skype chat support

where after big debates they started from telling us to wait a "tier 3" guy for about 1 hour and ended to say that they can't help !!!!!!!!

I have all this chats saved and we have spoken with

Jhoanna D. C.

Ignacio B.

James L.

Kristine Allen C

Victor S.

Jackie Lyn D. G.

and some others I think but is hard to search by history.

Their so called "help" was useless and just waisted our time and money Jackie Lyn D. G. also pointed that skype

does not have a phone support in order to lower the costs but is really HARD for me to understand how our numbers were gone .. and accept this as answer.

so guys if you buy numbers from skype and they just disappear .. don't contact skype to get them back fast because you picked

an low price carrier so .. bad luck ..

I'm writing this lines almost about 1 week since catastrophe (from my point of view) but I can prove with saved chats and I'll send those

chats to everybody interested in this subject .. even that my customer's attorneys are already handling this the damages but I've recommended skype

and since it turned out as this I can't just stand back .. so dear Skype friends employees .. you have my word that this post will get to at least

1000 forums .. paid posts by me .. so everybody will understand why not to use your services as I did ..

You can contact me at office at topsoft.ro for further details and chats transcriptions.

# Gert said on July 19, 2011 10:06 AM:
Thanks for sharing. Always good to find a real exrpet.
# MONCLER said on September 29, 2011 11:33 PM:
When starting and stopping IIS 7 application pools from command line with appcmd.exe, you should be aware

Leave a Comment

(required) 
(optional)
(required) 
Enter the code you see below


About Mike Volodarsky

For the past 5 years, I was the core Program Manager for Microsoft ASP.NET 2.0 and IIS 7.0 products. I drove the design and development of the IIS 7.0 web server core, the IIS FastCGI support, the AppCmd command line tool, the ASP.NET Integrated pipeline, and other special projects around server security, performance, and scalability. Now, I am working on my own on cutting edge web server tech on top of the Microsoft IIS platform, and continue blogging about it here.

About me



Until 2008, I was the core server Program Manager for the IIS 7.0 and ASP.NET 2.0 products at Microsoft.


View Michael Volodarsky's profile on LinkedIn


This is my company. We build expert performance and scalability tech for web applications on the Windows Server stack.
LeanServer Sentinel: Explore and instantly diagnose your production ASP.NET applications Sentinel beta starts on August 3rd! Register now!


Writings



TechNet Magazine
>Top 10 Performance Improvements in IIS 7.0

MSDN Magazine
>IIS 7.0: Build Web Server Solutions with End-To-End Extensibility
>IIS 7.0: Enhance Your Apps with the Integrated ASP.NET Pipeline
>IIS 7.0: Explore The Web Server For Windows Vista And Beyond
>Design and Deploy Secure Web Apps with ASP.NET 2.0 and IIS 6.0
>Fast, Scalable, and Secure Session State Management for Your Web Applications


Tools and Modules

LeechGuard
IconHandler 2.0
DirectoryListing
HttpRedirection
IIS Auth for Wordpress
iisschema.exe
PortCheck.exe v2.0

Popular Posts

- ASP.NET 2.0 Breaking Changes on IIS 7.0
- Develop IIS7 modules and handlers with .NET
- Troubleshoot IIS7 errors like a pro
- Troubleshooting 503 / "service unavailable" errors
- Troubleshooting "server not found" errors
- Create IIS7 sites, applications, and virtual directories
- Run Ruby on Rails with IIS FastCGI
- VS Debugging of ASP.NET applications on Windows Vista
- Stop hot-linking with IIS and ASP.NET

Tags

Search

Go

This Blog

Archives

Good IIS Blogs

Disclaimer

These postings are provided as is with no warranties, and confer no rights. The views expressed in this blog are entirely my own.

Syndication