-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart-alterego-webapp.sh
More file actions
executable file
·61 lines (50 loc) · 2.03 KB
/
start-alterego-webapp.sh
File metadata and controls
executable file
·61 lines (50 loc) · 2.03 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
#!/bin/bash
# 1. Set up application directory
APP_DIR="/home/alterego-vision/AlterEGO_v2/catkin_ws/src/alterego_webapp"
# 2. Correctly initialize NVM (Node Version Manager) to find the right Node.js version.
# This is the standard and most reliable way to use NVM in scripts.
export NVM_DIR="$HOME/.nvm"
if [ -s "$NVM_DIR/nvm.sh" ]; then
. "$NVM_DIR/nvm.sh"
else
# If NVM is not found, we can't continue.
exit 1
fi
# 3. Explicitly load environment variables from the .env file.
if [ -f "$APP_DIR/.env" ]; then
export $(grep -v '^#' "$APP_DIR/.env" | xargs)
fi
# 4. Dynamically find the path to the executables using 'which'.
# After loading NVM, 'which node' will now point to the correct (newer) version.
NODE_EXEC=$(which node)
FIREFOX_EXEC=$(which firefox)
# 5. Check if the executables were found. If not, exit.
if [ -z "$NODE_EXEC" ]; then
notify-send "AlterEgo WebApp Error" "Node.js executable not found."
exit 1
fi
if [ -z "$FIREFOX_EXEC" ]; then
notify-send "AlterEgo WebApp Error" "Firefox executable not found."
exit 1
fi
# 6. Set other environment variables and start the application.
export DISPLAY=:0
notify-send "AlterEgo WebApp" "Starting up, please wait..."
# 7. Change to the app directory and start the Node.js server.
# The --experimental-specifier-resolution=node flag will now be understood by the correct Node version.
# We redirect output to /dev/null to prevent it from creating files or showing in logs.
cd "$APP_DIR" || exit
"$NODE_EXEC" --experimental-specifier-resolution=node src/webapp.js > /dev/null 2>&1 &
# 8. Wait intelligently for the server to be ready on port 3000.
attempts=0
max_attempts=15 # Wait for a maximum of 15 seconds
while ! nc -z localhost 3000 && [ $attempts -lt $max_attempts ]; do
sleep 1
attempts=$((attempts+1))
done
if [ $attempts -eq $max_attempts ]; then
notify-send "AlterEgo WebApp Error" "Server failed to start on port 3000."
exit 1
fi
# 9. Start Firefox in kiosk mode now that the server is confirmed to be running.
"$FIREFOX_EXEC" --kiosk http://localhost:3000