Advertisement
qiwichupa

дичь для перезапуска постгреса лапками

Jul 19th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $logfile = "c:\logfile.log"
  2. $Services = Get-Service -Name PlugPlay, WerSvc # Сюда список проверяемых сервисов, "Get-Service *" чтобы посмотреть все имена
  3.  
  4. foreach ($service in $services) {
  5.  
  6.     #ПРОВЕРКА ВСЕХ УКАЗАННЫХ СЕРВИСОВ КРОМЕ ПОСТГРЕСА, заменить его имя
  7.     if ( ($service.Name -ne 'Postgres') -and ($service.Status -eq 'Stopped') ) {
  8.  
  9.         Get-Date | select  Date | Out-File -Append $logfile
  10.         "Нам пизда! " + $service.Name + " упал нахуй!" | Out-File -Append $logfile
  11.  
  12.         try {
  13.             "Стартуем!" | Out-File -Append $logfile
  14.             $service.Start()
  15.             }
  16.         catch { "Ваще пизда! " + $service.Name + " распидарасило и пиздец!" | Out-File -Append $logfile  }
  17.     }
  18.  
  19.  
  20.     # ПРОВЕРКА ПОСТГРЕСА, заменить имя его сервиса
  21.     if ( ($service.Name -eq 'Postgres') -and ($service.Status -eq 'Stopped') ) {
  22.     Get-Date | select  Date | Out-File -Append $logfile
  23.     "Ёбушки-воробушки, постгрес по пизде пошел!"  | Out-File -Append $logfile
  24.  
  25.      #все что ниже - надо проверять и тестить
  26.  
  27.      $env:PGDATA = Get-ChildItem c:\ -Recurse -Include 'postgresql.conf'  -File -WarningAction Ignore -ErrorAction Ignore | Select-Object -First 1  -ExpandProperty DirectoryName
  28.    
  29.      Start-Process 'C:\Program Files\PostgreSQL\9.4\bin\pg_ctl.exe' @('status') -Wait
  30.  
  31.      Start-Process 'C:\Program Files\PostgreSQL\9.4\bin\pg_ctl.exe' @('stop', '-m','fast') -Wait
  32.  
  33.      Start-Process 'C:\Program Files\PostgreSQL\9.4\bin\pg_ctl.exe' @('start') -Wait
  34.  
  35.      Start-Process 'C:\Program Files\PostgreSQL\9.4\bin\pg_ctl.exe' @('stop','-m','fast') -Wait
  36.  
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement