forked from steel-dev/steel-browser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·127 lines (108 loc) · 3.44 KB
/
entrypoint.sh
File metadata and controls
executable file
·127 lines (108 loc) · 3.44 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/bin/sh
set -e # Exit on error
# Function to log with timestamp
log() {
if [ "$DEBUG" = "true" ]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1"
fi
}
# Initialize DBus
init_dbus() {
log "Initializing DBus..."
mkdir -p /var/run/dbus
if [ -e /var/run/dbus/pid ]; then
rm -f /var/run/dbus/pid
fi
dbus-daemon --system --fork
sleep 2 # Give DBus time to initialize
if dbus-send --system --print-reply --dest=org.freedesktop.DBus \
/org/freedesktop/DBus org.freedesktop.DBus.ListNames >/dev/null 2>&1; then
log "DBus initialized successfully"
return 0
else
log "ERROR: DBus failed to initialize"
return 1
fi
}
# Verify Chrome and ChromeDriver installation
verify_chrome() {
log "Verifying Chrome installation..."
# Check Chrome binary and version
if [ ! -f "/usr/bin/chromium" ] && [ -z "$CHROME_EXECUTABLE_PATH" ]; then
log "ERROR: Chrome binary not found at /usr/bin/chromium and CHROME_EXECUTABLE_PATH not set"
return 1
fi
if [ -f "/usr/bin/chromium" ]; then
chrome_version=$(chromium --version 2>/dev/null || echo "unknown")
elif [ -n "$CHROME_EXECUTABLE_PATH" ] && [ -f "$CHROME_EXECUTABLE_PATH" ]; then
chrome_version=$("$CHROME_EXECUTABLE_PATH" --version 2>/dev/null || echo "unknown")
else
chrome_version="unknown"
fi
log "Chrome version: $chrome_version"
# Check ChromeDriver binary and version
if [ ! -f "/usr/bin/chromedriver" ]; then
log "ERROR: ChromeDriver not found at /usr/bin/chromedriver"
return 1
fi
chromedriver_version=$(chromedriver --version 2>/dev/null || echo "unknown")
log "ChromeDriver version: $chromedriver_version"
log "Chrome environment configured successfully"
return 0
}
# Start nginx with better error handling
start_nginx() {
if [ "$START_NGINX" = "true" ]; then
log "Starting nginx..."
nginx -c /app/api/nginx.conf
# Wait for nginx to start
max_attempts=10
attempt=1
while [ $attempt -le $max_attempts ]; do
if nginx -t >/dev/null 2>&1; then
log "Nginx started successfully"
return 0
fi
log "Attempt $attempt/$max_attempts: Waiting for nginx..."
attempt=$((attempt + 1))
sleep 1
done
log "ERROR: Nginx failed to start properly"
return 1
else
log "Skipping nginx startup (--no-nginx flag detected)"
return 0
fi
}
# Main execution
main() {
# Parse arguments
START_NGINX=true
for arg in "$@"; do
if [ "$arg" = "--no-nginx" ]; then
START_NGINX=false
break
fi
done
if [ "$DEBUG" = "true" ]; then
init_dbus || exit 1
verify_chrome || exit 1
fi
start_nginx || exit 1
# Set required environment variables
export CDP_REDIRECT_PORT=9223
export DISPLAY=:10
# Log environment state
log "Environment configuration:"
log "HOST=$HOST"
log "CDP_REDIRECT_PORT=$CDP_REDIRECT_PORT"
log "NODE_ENV=$NODE_ENV"
# Start the application
# Run the `npm run start` command but without npm.
# NPM will introduce its own signal handling
# which will prevent the container from waiting
# for a session to be released before stopping gracefully
log "Starting Steel Browser API..."
exec node ./api/build/index.js
}
main "$@"