-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-watchdog.ps1
More file actions
33 lines (28 loc) · 1.03 KB
/
Copy pathstart-watchdog.ps1
File metadata and controls
33 lines (28 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
$ErrorActionPreference = "Stop"
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
$WatchdogScript = Join-Path $Root "watch-proxy.ps1"
$WatchdogPidFile = Join-Path $Root ".watchdog.pid"
$stdout = Join-Path $Root "watchdog.stdout.log"
$stderr = Join-Path $Root "watchdog.stderr.log"
if (Test-Path $WatchdogPidFile) {
try {
$existingPid = [int](Get-Content -LiteralPath $WatchdogPidFile)
if (Get-Process -Id $existingPid -ErrorAction SilentlyContinue) {
Write-Host "watchdog already running"
Write-Host "PID: $existingPid"
exit 0
}
} catch {}
}
$powershell = (Get-Command powershell.exe).Source
$process = Start-Process `
-FilePath $powershell `
-ArgumentList @("-NoProfile", "-ExecutionPolicy", "Bypass", "-File", $WatchdogScript) `
-WorkingDirectory $Root `
-WindowStyle Hidden `
-RedirectStandardOutput $stdout `
-RedirectStandardError $stderr `
-PassThru
Set-Content -LiteralPath $WatchdogPidFile -Value $process.Id -Encoding ASCII
Write-Host "watchdog started"
Write-Host "PID: $($process.Id)"