Перезапуск пулов приложений

Microsoft.SystemCenter.Apm.Infrastructure.Monitoring.ApmAgent.RecycleIIS.Task (Task)

Эта задача осуществляет повторный запуск пулов приложений на целевых компьютерах.

Element properties:

TargetMicrosoft.SystemCenter.Apm.ApmAgent
AccessibilityInternal
CategoryMaintenance
EnabledTrue
RemotableFalse
Timeout300

Member Modules:

ID Module Type TypeId RunAs 
WA WriteAction Microsoft.Windows.ScriptWriteAction System.PrivilegedMonitoringAccount

Source Code:

<Task ID="Microsoft.SystemCenter.Apm.Infrastructure.Monitoring.ApmAgent.RecycleIIS.Task" Accessibility="Internal" Enabled="true" Target="AI!Microsoft.SystemCenter.Apm.ApmAgent" Remotable="false">
<Category>Maintenance</Category>
<WriteAction ID="WA" TypeID="Windows!Microsoft.Windows.ScriptWriteAction" RunAs="System!System.PrivilegedMonitoringAccount">
<ScriptName>ActivatedApmAgent.RecycleIIS.Task.vbs</ScriptName>
<Arguments/>
<ScriptBody><Script>

Option Explicit

SetLocale("en-us")

Const commandLine = "%windir%\system32\inetsrv\appcmd.exe list apppools /xml"

Dim WShell : Set WShell = CreateObject("wscript.shell")
Dim oExec : Set oExec = WShell.Exec(commandLine)

If Not oExec.StdOut.AtEndOfStream Then
Dim stdOutput : stdOutput = "" &amp; oExec.StdOut.ReadAll()
End If
Dim execResult : execResult = oExec.ExitCode

' Write error output and exit if result is not 0
If 0 &lt;&gt; execResult Then
Wscript.StdErr.Write stdOutput
Wscript.Quit execResult
Else
Dim objXMLDoc : Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.loadXml(stdOutput)

Dim xPath : xPath = "appcmd/APPPOOL"
Dim xmlNodes : Set xmlNodes = objXMLDoc.getElementsByTagName(xPath)

Dim apppool

For each apppool in xmlNodes

Dim appPoolState : appPoolState = UCase(apppool.Attributes.getNamedItem("state").text)
Dim appName : appName = apppool.Attributes.getNamedItem("APPPOOL.NAME").text

If(appPoolState = "STARTED") Then

Dim commandLineR : commandLineR = "%windir%\system32\inetsrv\appcmd.exe recycle apppool """ &amp; appName &amp; """"
Dim oExecR : Set oExecR = WShell.Exec(commandLineR)

Dim stdOutputR : stdOutputR = ""
If Not oExecR.StdOut.AtEndOfStream Then
stdOutputR = oExecR.StdOut.ReadAll()
End If
execResult = oExecR.ExitCode

' Write error output and exit if result is not 0
If 0 &lt;&gt; execResult Then
Wscript.StdErr.Write stdOutputR
Wscript.Quit execResult
Else
Wscript.StdOut.Write stdOutputR
End If
End If
Next
End If

Dim oAPI : Set oAPI = CreateObject("MOM.ScriptAPI")
Call oAPI.LogScriptEvent("ActivatedApmAgent.RecycleIIS.Task.vbs", 3201, 0, "Recycle Application Pools task done.")

Wscript.Quit execResult

On Error Resume Next
Wscript.StdErr.Write Err.Description
Wscript.Quit Err.Code

</Script></ScriptBody>
<TimeoutSeconds>300</TimeoutSeconds>
</WriteAction>
</Task>