-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenhands-gui.sh
More file actions
executable file
·196 lines (166 loc) · 5.61 KB
/
openhands-gui.sh
File metadata and controls
executable file
·196 lines (166 loc) · 5.61 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#!/bin/bash
# OpenHands GUI Background Launcher for Apple Silicon Macs (M1/M2/M3/M4/M5+)
# Tested on M1 MacBook running macOS Sequoia 15.7
# Based on proven working solution from GitHub issue #7618
set -e
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Configuration
OPENHANDS_URL="http://localhost:3000"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
LOG_FILE="$SCRIPT_DIR/openhands.log"
PID_FILE="$SCRIPT_DIR/openhands.pid"
# Load environment variables if available
if [ -f "$HOME/.openhands_env" ]; then
source "$HOME/.openhands_env"
fi
function show_usage() {
echo -e "${BLUE}OpenHands GUI Background Launcher${NC}"
echo ""
echo "Usage: $0 [start|start-browser|stop|restart|status|logs]"
echo ""
echo "Commands:"
echo " start - Start OpenHands in background (no browser)"
echo " start-browser - Start OpenHands in background and open browser"
echo " stop - Stop OpenHands"
echo " restart - Restart OpenHands"
echo " status - Check if OpenHands is running"
echo " logs - Show recent logs"
echo ""
}
function check_docker() {
if ! docker info >/dev/null 2>&1; then
echo -e "${RED}❌ Docker is not running. Starting Colima...${NC}"
colima start --cpu 2 --memory 4 --disk 30
sleep 5
fi
}
function wait_for_openhands() {
echo -e "${YELLOW}⏳ Waiting for OpenHands to start...${NC}"
for i in {1..30}; do
if curl -s "$OPENHANDS_URL" >/dev/null 2>&1; then
echo -e "${GREEN}✅ OpenHands is ready!${NC}"
return 0
fi
sleep 2
echo -n "."
done
echo -e "${RED}❌ OpenHands failed to start within 60 seconds${NC}"
return 1
}
function start_openhands() {
local open_browser=${1:-false}
if is_running; then
echo -e "${YELLOW}⚠️ OpenHands is already running at $OPENHANDS_URL${NC}"
if [ "$open_browser" = "true" ]; then
open "$OPENHANDS_URL"
fi
return 0
fi
echo -e "${BLUE}🚀 Starting OpenHands GUI with Apple Silicon optimizations...${NC}"
check_docker
# Clean up any orphaned containers
docker container prune -f >/dev/null 2>&1 || true
# Set platform for Apple Silicon (ARM64) compatibility
export DOCKER_DEFAULT_PLATFORM=linux/amd64
# Start OpenHands in background
docker run -d --pull=always \
-e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:0.57.0-nikolaik \
-e LOG_ALL_EVENTS=true \
-e BROWSER_ACTION_ENABLED=false \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$HOME/.openhands:/.openhands" \
-p 3000:3000 \
--add-host host.docker.internal:host-gateway \
--name openhands-app \
docker.all-hands.dev/all-hands-ai/openhands:0.57.0
# Container ID is returned by docker run -d, no need for PID file
# echo $! > "$PID_FILE"
if wait_for_openhands; then
if [ "$open_browser" = "true" ]; then
echo -e "${GREEN}🌐 Opening browser...${NC}"
open "$OPENHANDS_URL"
fi
echo -e "${GREEN}✅ OpenHands is running in background${NC}"
echo -e "${BLUE}🌐 UI available at: $OPENHANDS_URL${NC}"
echo -e "${BLUE}📝 Logs: docker logs -f openhands-app${NC}"
echo -e "${BLUE}🛑 Stop: $0 stop${NC}"
else
stop_openhands
exit 1
fi
}
function stop_openhands() {
echo -e "${YELLOW}🛑 Stopping OpenHands...${NC}"
# Stop main OpenHands container
docker stop openhands-app 2>/dev/null || true
docker rm openhands-app 2>/dev/null || true
# Clean up OpenHands runtime containers (they have random names but use the runtime image)
echo -e "${YELLOW}🧩 Cleaning up runtime containers...${NC}"
RUNTIME_CONTAINERS=$(docker ps -a --filter "ancestor=docker.all-hands.dev/all-hands-ai/runtime:0.57.0-nikolaik" --format "{{.ID}}" 2>/dev/null || true)
if [ -n "$RUNTIME_CONTAINERS" ]; then
echo "$RUNTIME_CONTAINERS" | xargs -r docker rm -f 2>/dev/null || true
fi
# Clean up any stopped containers (safe - only removes stopped ones)
docker container prune -f >/dev/null 2>&1 || true
# Clean up PID file
if [ -f "$PID_FILE" ]; then
rm "$PID_FILE"
fi
echo -e "${GREEN}✅ OpenHands fully cleaned up${NC}"
}
function restart_openhands() {
stop_openhands
sleep 2
start_openhands false
}
function is_running() {
docker ps --format "table {{.Names}}" | grep -q "openhands-app" 2>/dev/null
}
function show_status() {
if is_running; then
echo -e "${GREEN}✅ OpenHands is running${NC}"
echo -e "${BLUE}🌐 URL: $OPENHANDS_URL${NC}"
echo -e "${BLUE}📊 Container info:${NC}"
docker ps --filter "name=openhands-app" --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}"
else
echo -e "${RED}❌ OpenHands is not running${NC}"
fi
}
function show_logs() {
if is_running; then
echo -e "${BLUE}📝 OpenHands container logs:${NC}"
docker logs --tail 50 openhands-app
else
echo -e "${YELLOW}⚠️ OpenHands is not running${NC}"
fi
}
# Main command handling
case "${1:-start}" in
start)
start_openhands false
;;
start-browser)
start_openhands true
;;
stop)
stop_openhands
;;
restart)
restart_openhands
;;
status)
show_status
;;
logs)
show_logs
;;
*)
show_usage
exit 1
;;
esac