2016-12-27 1 views
0

서비스 충돌이 발생할 때마다 perl 스크립트를 실행하려고합니다. perl 스크립트는 서비스를 다시 시작하고 모든 개발자에게 메일을 보내려합니다.Windows 복구 서비스에서 '서비스 실행'옵션을 사용하여 장애 복구

여기에 Windows 복구 옵션을 사용했습니다. 여기에는 프로그램을 실행하는 옵션이 있습니다. 명령 줄 옵션에서 필요한 세부 사항을 채웠지 만 스크립트가 실행되지 않는 것처럼 보입니다. 이것에 대한 지식을 공유함으로써 나를 도울 수 있습니까?

Recovery tab configuration

나는 다시 시작 서비스 옵션을 시도하고는 잘 작동하지만 실행은 프로그램에서 스크립트 실행이되지 않습니다. 내가 놓친 게 있니? 이에 대한 의견은 도움이 될 것입니다.

답변

0

나는 최근에 정의 된 횟수로 서비스를 다시 시작하려고 시도하고 결론적으로 전자 메일 알림을 보내는 powershell 스크립트를 실행하는 복구 옵션을 구현했으며 최근 관련 로그가있는 txt 파일도 첨부합니다.

프로그램 : PowerShell.exe의
**하지 C를 다음과 같이

여러 번 시도 후

(그리고 내가 본 다른 모든 것들에도 불구하고) 서비스에서 복구 탭에서 필드의 구성은 \ 윈도우 \ System32 \ WindowsPowerShell \ v1.0 \ Powershell.exe

명령 줄 매개 변수 : -command "& {SomePath \ YourScript.ps1 '$ args [0]'$ args [1] '} "

예 : -command"& {C : \ PowershellScripts \ ServicesRecovery.ps 1 '서비스 이름'} "

** $ args는 스크립트에 전달되는 매개 변수입니다. 필수 사항은 아닙니다.

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 = "[email protected]" 
$FromAddress = "[email protected]" 

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 = "[email protected]" 
$FromAddress = "[email protected]" 

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 
: 여기

는 파워 쉘 스크립트입니다