Themen Programmatisch Recycling der Application-Pools im IIS 7

Erstellte ich eine C# Anwendung zu recyceln alle Anwendungspools in IIS, ein zu einer Zeit, die mit dem Microsoft.Web.Verwaltung.ApplicationPool-Klasse. Es gibt keine Methode, die auf ApplicationPool neu starten, die app-pool (bitte korrigiert mich wenn ich falsch Liege), so dass ich dachte, Sie würde nur noch ein stop und dann start. Es funktioniert gut für die meisten Teil, bis wir begannen, immer einige threads in einer app-pool, hingen in einer Endlosschleife.

Standardmäßig hat IIS hat einen 90-Sekunden - "Shutdown Time Limit", wo es wartet 90 Sekunden, bevor es beendet alle threads noch laufen, so dass ich nennen würde ApplicationPool.Stop(), und es würde 90 Sekunden, bis IIS beendet die app-pool, bevor es der Staat würde gestoppt werden, und ich könnte sagen, um erneut zu starten. Alles, was versuchen würde, drücken Sie eine beliebige Anwendungen mithilfe von app-pool, einen 503-Fehler Antwort für jene 90 Sekunden, bis ich beginnen konnte, den pool wieder.

Ich beschlossen, zu versuchen, und ändern Sie den "Shutdown Time Limit" programmatisch auf 5 Sekunden zu verringern die Anzahl der apps, die 503-Fehler, aber IIS ist, warten noch 90 Sekunden, bevor es beendet die Anwendung Pool. Unten ist meine Funktion zum Herunterfahren der Anwendung pool:

private void StopAppPool(ApplicationPool applicationPool)
{
    ObjectState state = applicationPool.State;
    TimeSpan previousShutdownTimeLimit = applicationPool.ProcessModel.ShutdownTimeLimit;
    applicationPool.ProcessModel.ShutdownTimeLimit = new TimeSpan(0, 0, 5);
    switch (state)
    {
        case ObjectState.Started:
            applicationPool.Stop();
            WL("Application Pool {0}'s state has gone from {1} to {2}", applicationPool.Name, state, applicationPool.State);
            break;
        case ObjectState.Starting:
        case ObjectState.Unknown:
            for (int i = 0; i < 180; i++)
            {
                WL("Application Pool {0}'s state is {1}.  Waiting for state to become Started", applicationPool.Name, state);
                Thread.Sleep(500);
                state = applicationPool.State;
                if (applicationPool.State == ObjectState.Started) { break; }
            }
            if (state == ObjectState.Started)
            {
                applicationPool.Start();
                WL("Application Pool {0}'s state has gone from {1} to {2}", applicationPool.Name, state, applicationPool.State);
            }
            else
            {
                WL("Error starting Application Pool {0}: Application Pool never stopped", applicationPool.Name);
            }

            break;
        case ObjectState.Stopped:
        case ObjectState.Stopping:
            WL("Application Pool {0} was already in a {1} state and has not been modified", applicationPool.Name, state);
            break;
        default:
            WL("Error stopping Application Pool {0}: Unexpected ObjectState \"{1}\"", applicationPool.Name, state);
            break;
    }

    state = applicationPool.State;
    for (int i = 0; i < 180 && state != ObjectState.Stopped; i++)
    {
        WL("Application Pool {0}'s state is {1}.  Waiting for state to become Stopped", applicationPool.Name, state);
        Thread.Sleep(500);
        state = applicationPool.State;
    }
    applicationPool.ProcessModel.ShutdownTimeLimit = previousShutdownTimeLimit;
}    

Warum nicht der ApplicationPool.ProcessModel.ShutdownTimeLimit scheinen zu beeinflussen, wie lange es dauert, IIS, tatsächlich töten Sie die Anwendung Pool? Gibt es trotzdem, um andere Anwendungen ab Erhalt der 503-Fehler, während ich versuche, um das Recycling der application pool?

  • Sie wollen wahrscheinlich nicht zu hören, aber warum auf der Erde würden Sie wollen, um das Recycling der app-pool?
InformationsquelleAutor Daryl | 2011-02-22
Schreibe einen Kommentar