29 lines
1008 B
Batchfile
29 lines
1008 B
Batchfile
@echo off
|
|
setlocal
|
|
|
|
set "TASK_NAME=DocuTranslate"
|
|
set "HEALTH_URL=http://127.0.0.1:8010/service/meta"
|
|
set "LOG_DIR=%~dp0logs"
|
|
set "LOG_FILE=%LOG_DIR%\watchdog.log"
|
|
|
|
if not exist "%LOG_DIR%" mkdir "%LOG_DIR%"
|
|
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
|
"$ErrorActionPreference = 'Stop'; try { $r = Invoke-WebRequest -UseBasicParsing -Uri '%HEALTH_URL%' -TimeoutSec 8; if ($r.StatusCode -eq 200) { exit 0 } } catch {}; exit 1"
|
|
|
|
if "%ERRORLEVEL%"=="0" exit /b 0
|
|
|
|
timeout /t 10 /nobreak >nul
|
|
|
|
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
|
"$ErrorActionPreference = 'Stop'; try { $r = Invoke-WebRequest -UseBasicParsing -Uri '%HEALTH_URL%' -TimeoutSec 8; if ($r.StatusCode -eq 200) { exit 0 } } catch {}; exit 1"
|
|
|
|
if "%ERRORLEVEL%"=="0" exit /b 0
|
|
|
|
echo [%DATE% %TIME%] Two health checks failed. Restarting %TASK_NAME%...>> "%LOG_FILE%"
|
|
schtasks /End /TN "%TASK_NAME%" >> "%LOG_FILE%" 2>&1
|
|
timeout /t 2 /nobreak >nul
|
|
schtasks /Run /TN "%TASK_NAME%" >> "%LOG_FILE%" 2>&1
|
|
|
|
exit /b 0
|