我是一名Java程序员,我接到了一项任务,要找出Apache服务器失败/超时的原因,因为它似乎每天至少发生5-10次。
我看了一下日志发现了这些
File does not exist: C:/Apache2/htdocs/favicon.ico
File does not exist: C:/Apache2/htdocs/browserconfig.xml
File does not exist: C:/Apache2/htdocs/selfupdate
Invalid URI in request GET /../../../../../../../../../../../
Invalid method in request ABCD / HTTP/1.1
Invalid method in request QUALYS / HTTP/1.1时不时会有新的事情发生,每天都会发生。我在谷歌上搜索并尝试了一些修复,但在日志中似乎出现了一些新的东西。
我确实在第一次失败、第二次失败和后续失败时将属性中的recovery选项卡选项设置为"Restart the service“,然后选中了stops errors的启用选项。
我决定编写一个PowerShell脚本来检查日志,并在服务器出现故障时重新启动它。
$services = Get-Service -Name Apache2.2
Get-Service | ? {
$services -contains $_.Name -and $_.fFailureActionsOnNonCrashFailures
-eq ‘True’
} | Restart-Service运行Get-Service -Name "Apache2.2“|选择对象-Property *
给了我
Name : Apache2.2
RequiredServices : {Afd, Tcpip}
CanPauseAndContinue : False
CanShutdown : False
CanStop : True
DisplayName : Apache2.2
DependentServices : {}
MachineName : .
ServiceName : Apache2.2
ServicesDependedOn : {Afd, Tcpip}
ServiceHandle :
Status : Running
ServiceType : Win32OwnProcess
Site :
Container :请帮帮忙。
我现在正在编写一个java程序(JAR文件),它将以管理员身份启动PowerShell并运行脚本以重新启动Apache。然后通过Task Scheduler将这个JAR文件设置为每3分钟运行一次。
我想知道如何通过PowerShell检查故障,而不是盲目地重启。任何更好的解决方案/建议都将不胜感激。
发布于 2017-11-06 05:11:39
What I would do is find the correlating event in the event logs, for when the service stops. Then right click and create a triggered script or email notification. The triggered PowerShell script would look like this.
$serviceCheck = Get-Service -Name Apache 2.2 | select status
if ($serviceCheck -eq "Running")
{
#donothing
}
else
{
#send email here and restart service
}
Another option would be to run the script as a function and set a sleep timer so it only runs every 5 minutes. That would look like this:
function Check-Service{
$serviceCheck = Get-Service -Name Apache 2.2 | select status
if ($serviceCheck.Status -eq "Running")
{
#donothing
}
else
{
#send email here and restart service
#you can also send an email from here, just make sure you know the smtp server address
}
}https://stackoverflow.com/questions/47091108
复制相似问题