【发布时间】:2017-11-03 08:11:29
【问题描述】:
我是一名 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
时不时会有新事物发生,而且每天都会发生。我用谷歌搜索并尝试了一些修复,但日志中似乎出现了一些新内容。
我确实在第一次失败、第二次失败和后续失败的属性中将恢复选项卡选项设置为“重新启动服务”,然后检查启用选项以停止出现错误。
我决定编写一个 PowerShell 脚本来检查日志并在失败时重新启动 Apache 服务器。
$services = Get-Service -Name Apache2.2
Get-Service | ? {
$services -contains $_.Name -and $_.fFailureActionsOnNonCrashFailures
-eq ‘True’
} | Restart-Service
运行 Get-Service -Name "Apache2.2" |选择对象-属性 *
给我
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。然后通过任务计划程序将此 JAR 文件设置为每 3 分钟运行一次。
我想知道如何通过 PowerShell 来检查故障,而不是盲目重启。任何更好的解决方案/建议将不胜感激。
【问题讨论】:
-
首先我不知道apache服务,但是服务真的有fFailureActionsOnNonCrashFailures这个属性吗?您可以使用此 get-service -name "Apache" 进行检查
-
@guiwhatsthat 即使我不确定,我也从微软论坛 SERVICE_FAILURE_ACTIONS_FLAG 中获取了 fFailureActionsOnNonCrashFailures。 get-service -name Apache2.2 给了我它的显示名称和状态。
-
与其盲目重启服务,不如找出它挂起的原因并解决问题。
-
当 Get-Service -Name "YOur service" | Select-Object -Property * 不显示您的 service_failure... 属性,那么您使用的命令对您没有帮助
-
@Tomalak 我明白,这是一种解决方法,直到我找出原因为止。
标签: powershell windows-server-2012 windows-server-2012-r2