Answers:
在“服务”应用程序下,选择有问题的服务的属性。
查看恢复选项卡-有各种各样的选项-我将“第一次和第二次失败”设置为重新启动服务,第三次设置为运行批处理程序,该程序将BLAT发出带有第三次失败通知的电子邮件。
您还应该将“重置失败计数”设置为1,以每天重置失败计数。
编辑:
看起来您可以通过命令行执行此操作:
SC failure w3svc reset= 432000 actions= restart/30000/restart/60000/run/60000
SC failure w3svc command= "MyBatchFile.cmd"
您的MyBatchFile.CMD文件如下所示:
blat - -body "Service W3svc Failed" -subject "SERVICE ERROR" -to Notify@Example.com -server SMTP.Example.com -f Administrator@Example.com
SC failure w3svc command= "MyBatchFile.cmd"
它应该是在路径或C:\ Windows \ System32下。如果使用完整路径,则可以将其放在任何目录中,即SC failure w3svc command= "c:\Stuff\MyBatchFile.cmd"
我在Windows 2008服务器上的HostForLife.eu上使用ServiceKeeper,它工作得很好。以前,我对ServiceHawk进行过评论,但是我更喜欢使用ServiceKeeper,因为它更易于管理和界面。
我最近实现了一个恢复选项,以运行Powershell脚本,该脚本尝试按规定的次数重新启动服务,并在结束时发送电子邮件通知。
经过几次尝试(尽管我已经看过所有其他事情),服务中“恢复”选项卡上的字段配置如下:
程序:Powershell.exe
**不是C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ Powershell.exe
命令行参数:-command“&{SomePath \ YourScript.ps1'$ args [0]''$ args [1]''$ args [n]'}”
例如:-命令“&{C:\ PowershellScripts \ ServicesRecovery.ps1'服务名称'}”
** $ args是将传递到脚本的参数。这些不是必需的。
这是powershell脚本:
cd $PSScriptRoot
$n = $args[0]
function CreateLogFile {
$events = Get-EventLog -LogName Application -Source SomeSource -Newest 40
if (!(Test-Path "c:\temp")) {
New-Item -Path "c:\temp" -Type directory}
if (!(Test-Path "c:\temp\ServicesLogs.txt")) {
New-Item -Path "c:\temp" -Type File -Name "ServicesLogs.txt"}
$events | Out-File -width 600 c:\temp\ServicesLogs.txt
}
function SendEmail {
$EmailServer = "SMTP Server"
$ToAddress = "Name@domain.com"
$FromAddress = "Name@domain.com"
CreateLogFile
$Retrycount = $Retrycount + 1
send-mailmessage -SmtpServer $EmailServer -Priority High -To $ToAddress -From $FromAddress -Subject "$n Service failure" `
-Body "The $n service on server $env:COMPUTERNAME has stopped and was unable to be restarted after $Retrycount attempts." -Attachments c:\temp\ServicesLogs.txt
Remove-Item "c:\temp\ServicesLogs.txt"
}
function SendEmailFail {
$EmailServer = "SMTP Server"
$ToAddress = "Name@domain.com"
$FromAddress = "Name@domain.com"
CreateLogFile
$Retrycount = $Retrycount + 1
send-mailmessage -SmtpServer $EmailServer -Priority High -To $ToAddress -From $FromAddress -Subject "$n Service Restarted" `
-Body "The $n service on server $env:COMPUTERNAME stopped and was successfully restarted after $Retrycount attempts. The relevant system logs are attached." -Attachments c:\temp\ServicesLogs.txt
Remove-Item "c:\temp\ServicesLogs.txt"
}
function StartService {
$Stoploop = $false
do {
if ($Retrycount -gt 3){
$Stoploop = $true
SendEmail
Break
}
$i = Get-WmiObject win32_service | ?{$_.Name -imatch $n} | select Name, State, StartMode
if ($i.State -ne "Running" -and $i.StartMode -ne "Disabled") {
sc.exe start $n
Start-Sleep -Seconds 35
$i = Get-WmiObject win32_service | ?{$_.Name -imatch $n} | select State
if ($i.state -eq "Running"){
$Stoploop = $true
SendEmailFail}
else {$Retrycount = $Retrycount + 1}
}
}
While ($Stoploop -eq $false)
}
[int]$Retrycount = "0"
StartService
这是我在类似线程上的回答希望这会有所帮助...
您可以安排一个像这样的简单vbs脚本,以便在需要时定期重新启动计算机上的服务。
strComputer =“。” strSvcName =“ YOUR_SERVICE_NAME” 设置objWMI = GetObject(“ winmgmts:\\”&strComputer&“ \ root \ cimv2”) 设置objService = objWMI.Get(“ Win32_Service.Name ='”&strSvcName&“'”) 如果objService.State =“已停止”,则 objService.StartService() 万一
有人在“超级用户”处提出了类似的问题:您可以安装监视Windows服务的工具。诸如Service Hawk之类的东西可以帮助您保持服务的启动,或者允许您安排自动重新启动(可能在夜间)以保持服务的平稳运行。