开发者

IIS7 restart issue

开发者 https://www.devze.com 2022-12-16 15:29 出处:网络
I have a webservice on one of my websites which restarts the websites app pool. The problem Im getting is the IIS7 app pool keeps stopping with the following warning and then error:

I have a webservice on one of my websites which restarts the websites app pool.

The problem Im getting is the IIS7 app pool keeps stopping with the following warning and then error:

Warning: A process serving application pool 'appPoolNameHere' exceeded time limits during shut down.

Error: Application pool 'appPoolNameHere' is being automatically disabled due to a series of failures in the process(es) serving that application pool.

The code I am using to do this is:

            try
        {

            var serverManager = new ServerManager();

            var currentPoolName = SettingsManager.AppPoolName;

            if (!string.IsNullOrEmpty(currentPoolName))
                serverManager.ApplicationPools[currentPoolName].Recycle();

            HttpRuntime.Close();
        }
        catch (Exception ex)
        {                
            var exceptionManager = ExceptionManagerFactory.GetExceptionManager();
            exceptionManager.LogException(ExceptionManager.Severities.Critical, ex,
                                          "App Pool restart failed");
        }

I am not getting any exceptions being thrown here, but the app pool is stopping, this doesnt happen all the time and is very hard to replicate, I have tried several different things even just hitting the hell out of that service and sometimes its fine other times it dies.

Is there any开发者_如何学运维thing I can do to fix this?

The reason I have to restart it is due to an external config file to the webconfig which deals with the url redirects which is updated from the admin system.

Thanks for any help with this.


Well I seem to have sorted (not fixed) the issue, with some tape and sticky-back-plastic.

The solution

Changed app pool setting: Rapid-Fail Protection to false

This stops IIS from killing the app pool after several failed requests to it.

I also added in retry system, so if the recycle request fails it waits for 10secs and tries again, it will do this 5 times before giving up and sending out an exception notice.

This has fixed the problem, and everything seems to be working well again, although something about this screams this is wrong!! at me.

Only if IIS would monitor other files in a website and restart the app pool when it saw a change.


I didn't work with Microsoft.Web.Administration namespace, but what about unloading application domain and sending request to your website so that to start application again?

Good example (2nd point) by Peter Bromberg how to do this.

Update.

Reading error stack

System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at Microsoft.Web.Administration.Interop.IAppHostMethodInstance.Execute()

I thought of most common reason: insufficient rights. All administrative actions require administrative rights. When code above is executed, which user account is impersonated? IUSR? Switch to any admin for that block and it should work without exception.

0

精彩评论

暂无评论...
验证码 换一张
取 消