アプリケーション プールのエラー設定 <failure>
概要
<applicationPools>
コレクション内の <add>
要素の <failure>
要素では、アプリケーション プールに障害が発生したときに実行するアクションを構成します。 <failure>
要素の autoShutdownExe、orphanActionExe、rapidFailProtection 属性は、アプリケーションのトラブルシューティングやデバッグ時に特に役立ちます。これは、これらの属性により、アプリケーションに障害が発生したときにインターネット インフォメーション サービス (IIS) で実行するアクション (エラーをログに記録したりデバッグしたりするための外部実行可能ファイルの実行など) を柔軟に指定できるためです。
互換性
バージョン | メモ |
---|---|
IIS 10.0 | <failure> 要素は、IIS 10.0 では変更されませんでした。 |
IIS 8.5 | <failure> 要素は、IIS 8.5 では変更されませんでした。 |
IIS 8.0 | <failure> 要素は IIS 8.0 では変更されませんでした。 |
IIS 7.5 | <failure> 要素は、IIS 7.5 では変更されませんでした。 |
IIS 7.0 | <failure> 要素が IIS 7.0 で導入されました。 |
IIS 6.0 | <failure> 要素は、IIS 6.0 の IIsApplicationPools メタベース プロパティの一部を置き換えます。 |
段取り
<applicationPools>
コレクションは、IIS 7 の既定のインストールに含まれています。
操作方法
ラピッド フェール保護の構成設定を編集する方法
インターネット インフォメーション サービス (IIS) マネージャーを開きます。
Windows Server 2012 または Windows Server 2012 R2 を使用している場合:
- タスク バーで、[サーバー マネージャー] をクリックし、[ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows 8 または Windows 8.1 を使用している場合:
- Windows キーを押しながら文字 X を押し、[コントロール パネル] をクリックします。
- [管理ツール] をクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
Windows Server 2008 または Windows Server 2008 R2 を使用している場合:
- タスク バーで、[スタート] ボタンをクリックし、[管理ツール]、[インターネット インフォメーション サービス (IIS) マネージャー] の順にクリックします。
Windows Vista または Windows 7 を使用している場合:
- タスク バーで、[スタート]、[コントロール パネル] の順にクリックします。
- [管理ツール] をダブルクリックし、[インターネット インフォメーション サービス (IIS) マネージャー] をダブルクリックします。
[接続] ウィンドウで、サーバー名を展開し、[アプリケーション プール] をクリックし、編集するアプリケーション プールをクリックします。
[操作] ウィンドウの [詳細設定...] をクリックします。
[詳細設定] ダイアログ ボックスで、編集するラピッド フェール保護プロパティをクリックし、ダイアログ ボックスのプロパティ値セクションの値を編集して [OK] をクリックします。 たとえば、[Failure Interval (minutes)] (失敗間隔 (分)) を「4」に変更し、[Maximum Failures] (最大障害数) を「4」にします。
構成
属性
属性 | 説明 | ||||||
---|---|---|---|---|---|---|---|
autoShutdownExe |
省略可能な文字列属性。 WWW サービスでアプリケーション プールがシャットダウンしたときに実行する実行可能ファイルを指定します。 autoShutdownParams 属性を使用して、実行可能ファイルにパラメーターを送信できます。 | ||||||
autoShutdownParams |
省略可能な文字列属性。 autoShutdownExe 属性で指定されている実行可能ファイルのコマンド ライン パラメーターを指定します。 | ||||||
loadBalancerCapabilities |
省略可能な列挙型属性。 ワーカー プロセスを開始できない場合 (要求キューがいっぱいになったり、アプリケーション プールがラピッド フェール保護されている場合など) の動作を指定します。 loadBalancerCapabilities 属性には、次のいずれかの値を指定できます。 既定値は HttpLevel です。
|
||||||
orphanActionExe |
省略可能な文字列属性。 WWW サービスでワーカー プロセスが孤立したときに実行する実行可能ファイルを指定します (orphanWorkerProcess 属性が true に設定されている場合)。 orphanActionParams 属性を使用して、実行可能ファイルにパラメーターを送信できます。 | ||||||
orphanActionParams |
省略可能な文字列属性。 orphanActionExe 属性によって指定された実行可能ファイルのコマンド ライン パラメーターを示します。 孤立したプロセスのプロセス ID を指定するには、"%1%" を使用します。 | ||||||
orphanWorkerProcess |
省略可能な Boolean 属性です。 アプリケーション プールで障害が発生したときに、ワーカー プロセスを終了するのではなく孤立状態に割り当てるかどうかを指定します。 既定値は false です。 |
||||||
rapidFailProtection |
省略可能な Boolean 属性です。 true に設定すると、次の場合にアプリケーション プール内のすべてのアプリケーションをサービスから削除するように WWW サービスに指示します。
true です。 |
||||||
rapidFailProtectionInterval |
省略可能な timeSpan 属性。 プロセスのエラー数がリセットされるまでの分数を指定します。 既定値は 00:05:00 (5 分) です。 |
||||||
rapidFailProtectionMaxCrashes |
省略可能な uint 属性。 rapidFailProtectionInterval 属性で指定された分数以内に許容されるエラーの最大数を指定します。 注: IIS 7.5 以降では、この値は 1 から 2147483647 の間である必要があります。 既定値は 5 です。 |
子要素
なし。
構成サンプル
次の構成サンプルでは、DefaultAppPool という名前の 1 つのアプリケーション プールに対してラピッド フェール保護を有効にし、5 分間のラピッド フェール保護間隔を構成し、分数以内の最大障害数を 5 に設定します。
<applicationPools>
<add name="DefaultAppPool">
<failure rapidFailProtection="true"
rapidFailProtectionInterval="00:05:00"
rapidFailProtectionMaxCrashes="5" />
</add>
<applicationPoolDefaults>
<processModel identityType="NetworkService" />
</applicationPoolDefaults>
</applicationPools>
サンプル コード
次のコード例では、サーバー上の DefaultAppPool のラピッド フェール保護を有効にしてから、保護間隔を 5 分に設定し、クラッシュの最大数を 5 に設定します。
AppCmd.exe
appcmd.exe set config -section:system.applicationHost/applicationPools /[name='DefaultAppPool'].failure.rapidFailProtection:"True" /commit:apphost
appcmd.exe set config -section:system.applicationHost/applicationPools /[name='DefaultAppPool'].failure.rapidFailProtectionInterval:"00:05:00" /commit:apphost
appcmd.exe set config -section:system.applicationHost/applicationPools /[name='DefaultAppPool'].failure.rapidFailProtectionMaxCrashes:"5" /commit:apphost
Note
AppCmd.exe を使用してこれらの設定を構成するときは、commit パラメーターを必ず apphost
に設定する必要があります。 これで、ApplicationHost.config ファイルの適切な場所セクションに構成設定がコミットされます。
C#
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools");
ConfigurationElementCollection applicationPoolsCollection = applicationPoolsSection.GetCollection();
ConfigurationElement addElement = FindElement(applicationPoolsCollection, "add", "name", @"DefaultAppPool");
if (addElement == null) throw new InvalidOperationException("Element not found!");
ConfigurationElement failureElement = addElement.GetChildElement("failure");
failureElement["rapidFailProtection"] = true;
failureElement["rapidFailProtectionInterval"] = TimeSpan.Parse("00:05:00");
failureElement["rapidFailProtectionMaxCrashes"] = 5;
serverManager.CommitChanges();
}
}
private static ConfigurationElement FindElement(ConfigurationElementCollection collection, string elementTagName, params string[] keyValues)
{
foreach (ConfigurationElement element in collection)
{
if (String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase))
{
bool matches = true;
for (int i = 0; i < keyValues.Length; i += 2)
{
object o = element.GetAttributeValue(keyValues[i]);
string value = null;
if (o != null)
{
value = o.ToString();
}
if (!String.Equals(value, keyValues[i + 1], StringComparison.OrdinalIgnoreCase))
{
matches = false;
break;
}
}
if (matches)
{
return element;
}
}
}
return null;
}
}
VB.NET
Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
Sub Main()
Dim serverManager As ServerManager = New ServerManager
Dim config As Configuration = serverManager.GetApplicationHostConfiguration
Dim applicationPoolsSection As ConfigurationSection = config.GetSection("system.applicationHost/applicationPools")
Dim applicationPoolsCollection As ConfigurationElementCollection = applicationPoolsSection.GetCollection
Dim addElement As ConfigurationElement = FindElement(applicationPoolsCollection, "add", "name", "DefaultAppPool")
If (addElement Is Nothing) Then
Throw New InvalidOperationException("Element not found!")
End If
Dim failureElement As ConfigurationElement = addElement.GetChildElement("failure")
failureElement("rapidFailProtection") = True
failureElement("rapidFailProtectionInterval") = TimeSpan.Parse("00:05:00")
failureElement("rapidFailProtectionMaxCrashes") = 5
serverManager.CommitChanges()
End Sub
Private Function FindElement(ByVal collection As ConfigurationElementCollection, ByVal elementTagName As String, ByVal ParamArray keyValues() As String) As ConfigurationElement
For Each element As ConfigurationElement In collection
If String.Equals(element.ElementTagName, elementTagName, StringComparison.OrdinalIgnoreCase) Then
Dim matches As Boolean = True
Dim i As Integer
For i = 0 To keyValues.Length - 1 Step 2
Dim o As Object = element.GetAttributeValue(keyValues(i))
Dim value As String = Nothing
If (Not (o) Is Nothing) Then
value = o.ToString
End If
If Not String.Equals(value, keyValues((i + 1)), StringComparison.OrdinalIgnoreCase) Then
matches = False
Exit For
End If
Next
If matches Then
Return element
End If
End If
Next
Return Nothing
End Function
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST");
var applicationPoolsCollection = applicationPoolsSection.Collection;
var addElementPos = FindElement(applicationPoolsCollection, "add", ["name", "DefaultAppPool"]);
if (addElementPos == -1) throw "Element not found!";
var addElement = applicationPoolsCollection.Item(addElementPos);
var failureElement = addElement.ChildElements.Item("failure");
failureElement.Properties.Item("rapidFailProtection").Value = true;
failureElement.Properties.Item("rapidFailProtectionInterval").Value = "00:05:00";
failureElement.Properties.Item("rapidFailProtectionMaxCrashes").Value = 5;
adminManager.CommitChanges();
function FindElement(collection, elementTagName, valuesToMatch) {
for (var i = 0; i < collection.Count; i++) {
var element = collection.Item(i);
if (element.Name == elementTagName) {
var matches = true;
for (var iVal = 0; iVal < valuesToMatch.length; iVal += 2) {
var property = element.GetPropertyByName(valuesToMatch[iVal]);
var value = property.Value;
if (value != null) {
value = value.toString();
}
if (value != valuesToMatch[iVal + 1]) {
matches = false;
break;
}
}
if (matches) {
return i;
}
}
}
return -1;
}
VBScript
Set adminManager = WScript.CreateObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set applicationPoolsSection = adminManager.GetAdminSection("system.applicationHost/applicationPools", "MACHINE/WEBROOT/APPHOST")
Set applicationPoolsCollection = applicationPoolsSection.Collection
addElementPos = FindElement(applicationPoolsCollection, "add", Array("name", "DefaultAppPool"))
If (siteElementPos = -1) Then
WScript.Echo "Element not found!"
WScript.Quit
End If
Set addElement = applicationPoolsCollection.Item(addElementPos)
Set failureElement = addElement.ChildElements.Item("failure")
failureElement.Properties.Item("rapidFailProtection").Value = true
failureElement.Properties.Item("rapidFailProtectionInterval").Value = "00:05:00"
failureElement.Properties.Item("rapidFailProtectionMaxCrashes").Value = 5
adminManager.CommitChanges()
Function FindElement(collection, elementTagName, valuesToMatch)
For i = 0 To CInt(collection.Count) - 1
Set element = collection.Item(i)
If element.Name = elementTagName Then
matches = True
For iVal = 0 To UBound(valuesToMatch) Step 2
Set property = element.GetPropertyByName(valuesToMatch(iVal))
value = property.Value
If Not IsNull(value) Then
value = CStr(value)
End If
If Not value = CStr(valuesToMatch(iVal + 1)) Then
matches = False
Exit For
End If
Next
If matches Then
Exit For
End If
End If
Next
If matches Then
FindElement = i
Else
FindElement = -1
End If
End Function