-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.bat
More file actions
68 lines (58 loc) · 1.92 KB
/
Copy pathrun.bat
File metadata and controls
68 lines (58 loc) · 1.92 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@echo off
setlocal
set "BASE_DIR=%~dp0"
set "PG_BIN=%BASE_DIR%postgres\bin"
set "PG_DATA=%BASE_DIR%postgres\data"
set "DB_HOST=localhost"
set "DB_PORT=5432"
set "DB_NAME=appdb"
set "DB_USER=appuser"
set "DB_PASSWORD=apppassword"
echo Starting PostgreSQL Core Server...
"%PG_BIN%\pg_ctl.exe" -D "%PG_DATA%" -l "%BASE_DIR%postgres\log.txt" start
if errorlevel 1 (
echo [ERROR] Failed to start PostgreSQL. Check postgres\log.txt for details.
pause
exit /b 1
)
:: Verification loop to ensure database engine availability
set /a ATTEMPTS=0
:waitloop
timeout /t 1 > nul
set /a ATTEMPTS+=1
"%PG_BIN%\pg_isready.exe" -h 127.0.0.1 -p 5432 > nul 2>&1
if %errorlevel% equ 0 goto dbready
if %ATTEMPTS% geq 10 (
echo [ERROR] Database server timeout after 10 seconds.
pause
exit /b 1
)
goto waitloop
:dbready
:: Fast native check/creation of target application database
if exist "%BASE_DIR%pwfile.txt" (
set /p PGPASSWORD=<"%BASE_DIR%pwfile.txt"
) else (
set "PGPASSWORD=%DB_PASSWORD%"
)
"%PG_BIN%\psql.exe" -h 127.0.0.1 -p 5432 -U %DB_USER% -d postgres -c "CREATE DATABASE appdb;" >nul 2>&1
set "PGPASSWORD="
echo [INFO] Database initialization check passed.
:: START THE APPLICATION BACKEND ENGINE
echo [INFO] Booting Node.js backend controller...
set "NODE_EXE=%BASE_DIR%node-bin\node.exe"
cd /d "%BASE_DIR%"
start "ZSecTools Backend Log" cmd /k ""%NODE_EXE%" ".\backend\src\server.js""
:: Give backend a brief moment to boot then launch front-end entry
timeout /t 2 /nobreak > nul
start "" "http://localhost:3000"
echo ===================================================
echo ZSecTools application is up and running!
echo Minimize this window. Press any key to stop the app.
echo ===================================================
pause > nul
echo Shutting down database engine context...
"%PG_BIN%\pg_ctl.exe" -D "%PG_DATA%" stop
echo Cleanup completed. Goodbye!
timeout /t 2 > nul
endlocal