0

スクリプトを編集する必要があります。2 つの Windows Server 2008 R2 上にあるサービスがあります。それらは負荷分散されています。プライマリ サーバーとセカンダリ サーバーでサービスを開始するスクリプトを実行するときに必要なので、両方のサーバーでサービスを開始する前に、プライマリ サーバーが起動して実行されていることを確認してから続行します。通常どおり、両方のサーバーでサービスを開始します。

# Start Appian
function StartAppian {
  $APNSVC = Get-Service -Name $AppianService

  if (!$APNSVC) {
    Write-Host "Appian Service does not exist"
    return
  }
  # Check to see if Appian's service is already started
  if ($APNSVC.Status -eq "Running") {
    if ($LB) {
      if ($MULEAPNSVC.Status -eq "Running") {
        Write-Host "Appian Service on the Load Balanced Server already is started!" -ForegroundColor Yellow
        return
      }
    }

    Write-Host "Appian Service already is started!" -ForegroundColor Yellow
    Read-Host "Press any key to return"
    return
  }

  # Check if DEV's Process Design has a writing_*.kdb file and delete it
  if ($Server -eq "DEV") {
    #gw1
    if (Test-Path $APPIAN_HOME\server\process\design\gw1\writing_*.kdb) {
      Write-Host "Removing writing_*.kdb from GW1" -ForegroundColor Yellow
      Remove-Item $APPIAN_HOME\server\process\design\gw1\writing_*.kdb
    }
    #gw2
    if (Test-Path $APPIAN_HOME\server\process\design\gw2\writing_*.kdb) {
      Write-Host "Removing writing_*.kdb from GW2" -ForegroundColor Yellow
      Remove-Item $APPIAN_HOME\server\process\design\gw2\writing_*.kdb
    }
  }
  Write-Host "Starting Appian"

  # Place the name of the service here to start for Appian
  Start-Service $AppianService
  Notify("StartAppian")
  if ($LB) {
    (Get-Service $MULEAPNSVC.Name -ComputerName $MULE).Start()
    Write-Host "Starting Mule's Appian" -ForegroundColor Magenta
  }

  cmd.exe "/C $APPIAN_HOME\server\_scripts\diagnostic\checkengine.bat -s >    $logdir\Startup.log"

  # These lines check the Startup log for fatals and errors at the beginning
  $fatals = Select-String FATAL $logdir\Startup.log
  $errs = Select-String ERROR $logdir\Startup.log

  # Check for errors and fatals again
  $fatals = Select-String FATAL $logdir\Startup.log
  $errs = Select-String ERROR $logdir\Startup.log

  Write-Host "Still warnings or Errors in CE" -ForegroundColor Yellow
  # Increment times
  $times = $times + 1

  # If times > threshold, email out error message
  if ($times -gt $threshold) {
    SendAlert("There is a problem with Appian - It won't start")
    Write-Host "There was a problem with Appian..it took too long to start -  emailing alert" -ForegroundColor Red
    Read-Host "Press any key to exit"
  }
}
Write-Host "Appian Started" -ForegroundColor Green
Read-Host "Press any key to return"
}
4

2 に答える 2

0

他の提案はありますか?

if (Test-Connection ServerName -Count 1 -Quiet) {
Write-Host "Host avalible"
}

else {
Write-Host "Host unavalible"
Exit
}

これは機能しません。サーバーが稼働しているかどうかをテストし、稼働していない場合はスクリプトを終了し、稼働している場合はスクリプトを続行します。これを ISE でテストすると動作しますが、スクリプトを起動すると動作しません

于 2016-09-15T18:50:04.990 に答える
0

これは、スクリプトの開始時に単純な Test-Connection を使用して行うことができます。

if ($ping = Test-Connection -ComputerName PrimaryServerName -Quiet) {
Write-Host "Host avalible"
}

else {
Write-Host "Host unavalible"
Exit
}
于 2016-09-13T14:09:08.887 に答える