-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathocserv_server.sh
More file actions
executable file
·59 lines (49 loc) · 1.53 KB
/
ocserv_server.sh
File metadata and controls
executable file
·59 lines (49 loc) · 1.53 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
#!/bin/bash
set -e
DEBUG=${DEBUG:-0} # Default to 0 if not set
# -----------------------------
# Forward signals to child processes
# -----------------------------
# shellcheck disable=SC2064
trap "echo '[INFO] Caught SIGTERM, stopping...'; kill -TERM \$OCSERV_PID \$API_PID \$WEBHOOK_PID 2>/dev/null" SIGTERM SIGINT
# -----------------------------
# migrating database
# -----------------------------
echo "[INFO] Starting migrating database schemas..."
api migrate
# -----------------------------
# Start API service as non-root user
# -----------------------------
echo "[INFO] Starting API service..."
if [ "$DEBUG" = "1" ]; then
api serve -d &
else
api serve &
fi
API_PID=$!
# -----------------------------
# Start Webhook service as non-root user
# -----------------------------
echo "[INFO] Starting Webhook service..."
webhook &
WEBHOOK_PID=$!
# -----------------------------
# Start ocserv as root
# -----------------------------
echo "[INFO] Starting ocserv..."
/usr/sbin/ocserv --foreground --debug=999 --config=/etc/ocserv/ocserv.conf &
OCSERV_PID=$!
# -----------------------------
# Wait for any process to exit
# -----------------------------
wait -n
# -----------------------------
# If one process exits, terminate the others
# -----------------------------
echo "[INFO] One of the processes exited, stopping all services..."
kill -TERM $OCSERV_PID $API_PID $WEBHOOK_PID 2>/dev/null || true
# -----------------------------
# Wait for all processes to clean up
# -----------------------------
wait
echo "[INFO] All services stopped."