-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.sh
More file actions
53 lines (43 loc) · 1.64 KB
/
Copy pathrun.sh
File metadata and controls
53 lines (43 loc) · 1.64 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
#!/bin/bash
BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export PATH="$BASE_DIR/node-bin/bin:$PATH"
export DB_HOST="localhost"
export DB_PORT="5432"
export DB_NAME="appdb"
export DB_USER="appuser"
export DB_PASSWORD="apppassword"
echo "Booting up environment dependencies..."
# Detect if using portable postgres or system host daemon
if [ -f "$BASE_DIR/postgres/bin/pg_ctl" ]; then
echo "[INFO] Initializing portable database instance..."
"$BASE_DIR/postgres/bin/pg_ctl" -D "$BASE_DIR/postgres/data" -l "$BASE_DIR/postgres/log.txt" start
else
echo "[INFO] Bypassing localized db execution. Target system environment engine validation..."
fi
# Explicit validation loop using pg_isready or manual sleep
sleep 2
# Boot backend logic in an asynchronous sub-shell process
echo "[INFO] Launching ZSecTools Backend Service Engine..."
cd "$BASE_DIR"
node ./backend/src/server.js &
BACKEND_PID=$!
echo "==================================================="
echo " ZSecTools running in interactive shell session."
echo " Application active on http://localhost:3000"
echo " Press CTRL+C to safely terminate processes."
echo "==================================================="
# Keep script interactive and handle graceful teardown signals
cleanup() {
echo -e "\nIntercepted shutdown signal. Cleaning up active processes..."
kill $BACKEND_PID 2>/dev/null
if [ -f "$BASE_DIR/postgres/bin/pg_ctl" ]; then
"$BASE_DIR/postgres/bin/pg_ctl" -D "$BASE_DIR/postgres/data" stop
fi
echo "Services stopped. System clear."
exit 0
}
trap cleanup SIGINT SIGTERM
# Lock interactive terminal visibility loop
while true; do
sleep 1
done