Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $logfile = "c:\logfile.log"
- $Services = Get-Service -Name PlugPlay, WerSvc # Сюда список проверяемых сервисов, "Get-Service *" чтобы посмотреть все имена
- foreach ($service in $services) {
- #ПРОВЕРКА ВСЕХ УКАЗАННЫХ СЕРВИСОВ КРОМЕ ПОСТГРЕСА, заменить его имя
- if ( ($service.Name -ne 'Postgres') -and ($service.Status -eq 'Stopped') ) {
- Get-Date | select Date | Out-File -Append $logfile
- "Нам пизда! " + $service.Name + " упал нахуй!" | Out-File -Append $logfile
- try {
- "Стартуем!" | Out-File -Append $logfile
- $service.Start()
- }
- catch { "Ваще пизда! " + $service.Name + " распидарасило и пиздец!" | Out-File -Append $logfile }
- }
- # ПРОВЕРКА ПОСТГРЕСА, заменить имя его сервиса
- if ( ($service.Name -eq 'Postgres') -and ($service.Status -eq 'Stopped') ) {
- Get-Date | select Date | Out-File -Append $logfile
- "Ёбушки-воробушки, постгрес по пизде пошел!" | Out-File -Append $logfile
- #все что ниже - надо проверять и тестить
- $env:PGDATA = Get-ChildItem c:\ -Recurse -Include 'postgresql.conf' -File -WarningAction Ignore -ErrorAction Ignore | Select-Object -First 1 -ExpandProperty DirectoryName
- Start-Process 'C:\Program Files\PostgreSQL\9.4\bin\pg_ctl.exe' @('status') -Wait
- Start-Process 'C:\Program Files\PostgreSQL\9.4\bin\pg_ctl.exe' @('stop', '-m','fast') -Wait
- Start-Process 'C:\Program Files\PostgreSQL\9.4\bin\pg_ctl.exe' @('start') -Wait
- Start-Process 'C:\Program Files\PostgreSQL\9.4\bin\pg_ctl.exe' @('stop','-m','fast') -Wait
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement