-
-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathdocker-start.sh
More file actions
66 lines (52 loc) · 1.5 KB
/
docker-start.sh
File metadata and controls
66 lines (52 loc) · 1.5 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
#!/bin/bash
set -e
ENGINE_LOG_LEVEL=${LOG_LEVEL:-info}
if [ -x /usr/local/bin/nexterm-engine ]; then
LOCAL_ENGINE_TOKEN=$(head -c 32 /dev/urandom | od -An -tx1 | tr -d ' \n')
export LOCAL_ENGINE_TOKEN
echo "[nexterm] Starting server..."
node server/index.js &
SERVER_PID=$!
sleep 2
mkdir -p /tmp/nexterm-engine
cat > /tmp/nexterm-engine/config.yaml <<EOF
server_host: "127.0.0.1"
server_port: ${CONTROL_PLANE_PORT:-7800}
registration_token: "$LOCAL_ENGINE_TOKEN"
tls: false
EOF
STOPPING=false
start_engine() {
echo "[nexterm] Starting local engine..."
cd /tmp/nexterm-engine && /usr/local/bin/nexterm-engine &
ENGINE_PID=$!
cd /app
}
cleanup() {
STOPPING=true
[ -n "$ENGINE_PID" ] && kill "$ENGINE_PID" 2>/dev/null
[ -n "$SERVER_PID" ] && kill "$SERVER_PID" 2>/dev/null
wait
exit 0
}
trap cleanup SIGINT SIGTERM
start_engine
while true; do
wait -n $SERVER_PID $ENGINE_PID 2>/dev/null || true
if ! kill -0 "$SERVER_PID" 2>/dev/null; then
echo "[nexterm] Server exited, shutting down..."
cleanup
fi
if [ "$STOPPING" = true ]; then
break
fi
if ! kill -0 "$ENGINE_PID" 2>/dev/null; then
echo "[nexterm] Engine crashed, restarting in 3 seconds..."
sleep 3
start_engine
fi
done
else
echo "[nexterm] Starting server..."
exec node server/index.js
fi